I try where
query in json structure. But always returns null
. Am I doing wrong ?
My scope method in Model :
public function scopeWhereDeveloper(Builder $scope)
{
return $scope->where('parameters->developer','yes');
}
My static method in Model :
public static function getDeveloper($columns = ['*'])
{
return static::whereDeveloper()->first($columns);
}
Migration :
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 method :
/** @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);
}
So what I do ?
So interesting.When I using this query :
return->where('parametersdeveloper','yes');
always returns null in. But when I test inHomeController
with ::getDeveloper()` then I can get the user. Why did this happen ?