小编Nic*_*ank的帖子

在VueJS组件中使用sass变量

对于需要使用变量的VueJS组件,我遇到了一个相当简单的问题.问题在于让sass在组件内注册变量.

我尝试导入_variables.scss包含我的变量的文件,但没有运气.在这一点上,非常感谢任何指导,或者如果组件有另一种方式来继承样式.

MyComponent.vue

<template>
    <div class="my-color"></div>
</template>
<style lang="sass">
    .my-color {
        color: $primary-color;
    }
</style>
<script>
    export default{
        data(){
            return {}
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

Gulpfile.js

var elixir = require('laravel-elixir');
require('laravel-elixir-vueify');

elixir(function(mix) {
    mix.browserify('main.js');
    mix.sass('app.scss');
});
Run Code Online (Sandbox Code Playgroud)

app.scss

@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";
@import "modules/variables";
Run Code Online (Sandbox Code Playgroud)

variables.scss

$primary-color: #BA2731; //Red
Run Code Online (Sandbox Code Playgroud)

sass laravel vue.js laravel-elixir

11
推荐指数
3
解决办法
1万
查看次数

Laravel:创建可空的 morphs() 关系

我想创建一个一对一的多态关系允许空关系。

例子:

  Schema::create('ps_assistances', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('assistance_number', 50)->nullable();
            $table->morphs('assitanceable')->nullable();
  });
Run Code Online (Sandbox Code Playgroud)

但是这个例子在将“->nullable()”赋值给 morph 列时返回 null。

我尝试手动创建 _type 和 _id 并且它工作正常。

手动变形列的示例:

  Schema::create('ps_assistances', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('assistance_number', 50)->nullable();
            $table->string('assitanceable_type')->nullable();
            $table->unsignedBigInteger('assitanceable_id')->nullable();
  });
Run Code Online (Sandbox Code Playgroud)

我想知道是否存在更好的方法来实现一对一的多态关系可空。

php relationship laravel

8
推荐指数
2
解决办法
2836
查看次数

使用Laravel Eloquents HasManyThrough通过多态关系与多个关系

我有一个相当简单的应用程序,用户可以报告其他用户的评论和食谱.我使用多态关系来存储报告.哪个工作正常; 但是,我现在正试图让用户犯下的罪行.

获取用户报告不是问题,这可以直接使用,user->reports()但我非常希望获得其他人报告所述用户的报告.我可以使用hasManyThrough关系或查询来实现这一点,但一次只能在一个模型上使用.

恩.

public function offenses() {
    return $this->hasManyThrough('Recipe', 'Reports');
}
Run Code Online (Sandbox Code Playgroud)

要么

->with('user.recipe.reports')
Run Code Online (Sandbox Code Playgroud)

问题是我的可报告对象不仅仅是食谱,它可能是注释,图像等.因此,不必使用多个函数,逻辑方法是以某种方式解析hasManyThrough各种参数之间的关系.

理论上看起来像这样:

public function offenses() {
    return $this->hasManyThrough(['Recipe', 'RecipeComments'], 'Reports');
}
Run Code Online (Sandbox Code Playgroud)

这有可能吗?有一些没有文档的语法?如果不是,有任何聪明的解决方法/黑客?

可能的方案?

可接受的解决方案是在我的报告表上添加另一列并且只添加这样的offender_id吗?

ID | User_id | Offender_id | Reportable_type | Reportable_id

这意味着我可以在我的用户模型上建立关系,通过该列连接攻击.但这会被视为多余吗?由于我已经通过可报告模型获得了罪犯?


楷模

多态模型

class Report extends Model {
    public function reportable() {
        return $this->morphTo();
    }

    public function User() {
        return $this->belongsTo('App\User');
    }
}
Run Code Online (Sandbox Code Playgroud)

食谱模型

class Recipe extends Model {
    public function user() {
        return $this->belongsTo('App\User');
    }

    public function reports() …
Run Code Online (Sandbox Code Playgroud)

php polymorphism laravel laravel-5

7
推荐指数
1
解决办法
2954
查看次数

使用Windows身份验证在MVC4站点上为HTTP请求验证角度

我目前正在开发使用网站AngularJS,应用程序是为了POSTGET数据和从已经运行的MVC4应用.此MVC4应用程序正在使用Windows身份验证.

我可以通过浏览器直接访问MVC4应用程序并导航返回JSON的URL .现在,我只是手动下载了这个JSON并用它构建了应用程序.

当我直接从我的AngularJS应用程序请求服务器时,我的问题出现了.我试图使用基本身份验证在另一台服务器上工作,这很好.但现在我需要使用NTLM身份验证来使用Windows身份验证.

我研究了构建Type 1消息并在授权标题中设置它,但我很快就被淹没了.

我觉得服务器和客户端之间需要大量的通信,只是为了进行身份验证,使得使用AngularJS和Windows身份验证(NTLM身份验证)没有吸引力?我该如何解决这个问题?

asp.net asp.net-mvc windows-authentication angularjs angularjs-http

5
推荐指数
1
解决办法
872
查看次数

Laravel Eloquent:获取包含两个特定关系的记录

我有一个项目,用户可以在其中与其他用户创建对话。用户可以进行对话belongsToMany,用户可以belongsToMany进行对话。

我现在需要获取两个特定用户参与的对话。

我尝试了多种解决方案的组合whereIn,并尝试了以下方法:

$c = Conversation::whereHas('users', function($q)
     {
         $q->whereIn('user_id', array(1,3));
     })
    ->get();
Run Code Online (Sandbox Code Playgroud)

这里的问题是获取包含whereIn('user_id', [1,3])1 或 3的记录。我需要它返回包含1和 3 的记录。

对话模型

class Conversation extends Model {

    public function users(){
        return $this->belongsToMany('App\User');
    }
}
Run Code Online (Sandbox Code Playgroud)

用户模型

class User extends Model {

    public function conversations(){
        return $this->belongsToMany('App\Conversation');
    }

}
Run Code Online (Sandbox Code Playgroud)

表格

对话:

编号 | 主题

对话用户:

编号 | 用户 ID | 对话id

来自表conversation_user的数据

在此输入图像描述

php has-and-belongs-to-many laravel eloquent laravel-5

4
推荐指数
1
解决办法
1896
查看次数

Laravel多态嵌套关系显示无法解释的行为

我正在使用多态关系来处理食谱和评论的报告.我在查询中包含多态对象没有问题,但是当我希望还包括所述多态对象的所有者(用户)时,问题就出现了.

起初我尝试了以下方法:

尝试1.控制器功能:

public function getReports() {
    return Report::orderBy('created_at', 'DESC')
        ->with('reportable', 'reportable.user')
        ->get();
}
Run Code Online (Sandbox Code Playgroud)

这导致没有错误,这很好,但它也没有在结果中包括用户.

查看数据:http://pastebin.com/DDfM3Ncj

尝试2.为多态报表模型添加了代码(可以在底部看到):

protected $appends = array('target');

public function getTargetAttribute() {
    return $this->reportable->user;
}
Run Code Online (Sandbox Code Playgroud)

这正确地导致了一个"目标"被添加到我的结果中,持有可报告对象的用户.然而,这个ALSO神秘地将用户添加到我的可报告对象,这是我最初想要的,但现在是一个问题,因为我们让用户处于目标之下.

查看数据:http://pastebin.com/4DD8imbN


如何获得多态关系的用户而不会突然结束两个.

注意:(以下代码可能不需要回答)


调节器

public function getReports(t) {
    return Report::orderBy('created_at', 'DESC')
        ->with('reportable')
        ->get();
}
Run Code Online (Sandbox Code Playgroud)

楷模

多态模型

class Report extends Model {
    public function reportable() {
        return $this->morphTo();
    }

    public function User() {
        return …
Run Code Online (Sandbox Code Playgroud)

php polymorphism laravel laravel-5

2
推荐指数
1
解决办法
572
查看次数

在没有全局范围的情况下使用Laravel触摸

概念问题: 在使用touches属性时,我有一个非常简单的问题,即自动更新依赖模型的时间戳; 它正确地这样做但也适用于全局范围.

有没有办法关闭此功能?或者专门要求自动 touches忽略全局范围?


具体示例:更新配料模型时,应触及所有相关配方.这样可以正常工作,除了我们globalScope根据区域设置分离配方,在应用触摸时也会使用它.


成分模型:

class Ingredient extends Model
{
    protected $touches = ['recipes'];

    public function recipes() {
        return $this->belongsToMany(Recipe::class);
    }

}
Run Code Online (Sandbox Code Playgroud)

食谱型号:

class Recipe extends Model
{
    protected static function boot()
    {
        parent::boot();
        static::addGlobalScope(new LocaleScope);
    }

    public function ingredients()
    {
        return $this->hasMany(Ingredient::class);
    }
}
Run Code Online (Sandbox Code Playgroud)

区域范围:

class LocaleScope implements Scope
{
    public function apply(Builder $builder, Model $model)
    {
        $locale = app(Locale::class);

        return $builder->where('locale', '=', $locale->getLocale());
    }

}
Run Code Online (Sandbox Code Playgroud)

php global-scope laravel

2
推荐指数
1
解决办法
6036
查看次数

用corona sdk重新加载游戏

我正在创建我的第一个iPhone游戏,无法弄清楚如何重新加载我的游戏.

我正在使用coronaSDK并尝试使用他们的composer API.当玩家死亡时,出现一个"再次播放"的按钮,当他触摸它时,我将他引导到一个名为"reload.lua"的场景中composer.gotoScene("reload").

在这个场景中,我有以下代码:

function scene:show(event)
    local sceneGroup = self.view
    local phase = event.phase

    if (phase == "will") then

    elseif (phase == "did") then
        local replay = display.newImage('star1.png', 100, 300)
        composer.removeScene("level1")
        composer.gotoScene("level1")
    end
end
Run Code Online (Sandbox Code Playgroud)

但是,这仅level1在现有的基础上添加,并且不会删除已使用的那个.关于如何成功删除level1或重新加载我的游戏的任何想法?

lua reload playback scene coronasdk

1
推荐指数
1
解决办法
1803
查看次数