Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel json在哪里不工作_Php_Sql_Json_Laravel - Fatal编程技术网

Php Laravel json在哪里不工作

Php Laravel json在哪里不工作,php,sql,json,laravel,Php,Sql,Json,Laravel,我尝试在json结构中进行where查询。但总是返回null。我做错了吗 模型中的我的作用域方法: public function scopeWhereDeveloper(Builder $scope) { return $scope->where('parameters->developer','yes'); } public static function getDeveloper($columns = ['*']) { return static::whereDe

我尝试在json结构中进行
where
查询。但总是返回
null
。我做错了吗

模型中的我的作用域方法:

public function scopeWhereDeveloper(Builder $scope)
{
  return $scope->where('parameters->developer','yes');
}
public static function getDeveloper($columns = ['*'])
{
    return static::whereDeveloper()->first($columns);
}
我在模型中的静态方法:

public function scopeWhereDeveloper(Builder $scope)
{
  return $scope->where('parameters->developer','yes');
}
public static function getDeveloper($columns = ['*'])
{
    return static::whereDeveloper()->first($columns);
}
迁移:

public function up()
    {
        Schema::create('admins', function(Blueprint $table) {
            $table->increments('id');
            $table->string('full_name');
            $table->string('user_name')->unique();
            $table->string('email')->unique();
            $table->string('password');
            $table->json('parameters')->nullable();
            $table->timestamps();
            $table->rememberToken();
        });
    }
试验方法:

/** @test */
public function it_can_get_admin_developer_by_parameter()
{
    $admin = create(Admin::class, ['parameters' => ['developer' => 'yes']]);

    $developer = Admin::getDeveloper();

    dd($developer); // return null

    $this->assertEquals($admin->email,$developer->email);

}
那我该怎么办


非常有趣。当我使用这个查询时:
return->where('parametersdeveloper','yes')在中始终返回null。但是当我使用::getDeveloper()在
HomeController
中测试时,我就可以得到用户。为什么会这样


不要用
where
前缀命名作用域。Eloquent会假设您试图使用速记来表示
->where('developer')


将您的作用域重命名为类似于
scopeDeveloper

什么是您的Laravel版本?Laravel版本是
5.6
在您的测试中
dd($admin->getAttributes())
的结果是什么?
数组:8[“全名”=>“Jalen”“用户名”=>“mertz.kevon”“电子邮件”=>”rwill@kozey.net“密码”=>“$2y$04$LJ9XSw1cu1i8e.Wurqncze09t4zxfiutagzluuk2hbc.52kcba”“参数”=>“{”开发者“:“是的”}”更新于“=>”2018-04-16 15:30:51”“创建于“=>”2018-04-16 15:30:51”“id”=>1]
@ysfkaya如果您将其重命名为
scopeDeveloper
您需要将其用作
Model::developer()
是的,我注意到,它在
Controller
中工作,但在测试中仍然返回
null
。你知道为什么吗?