LIKE %% 在 laravel 5.5 中不工作
LIKE %% not working in laravel 5.5
我试图在 laravel 中进行搜索,但在 laravel 中使用
User::where('first_name', 'LIKE %', $name);
没用。
这是我的用户模型。
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable {
use Notifiable;
protected $table = 'users';
protected $fillable = [
'first_name',
'last_name',
'email',
'bio',
'pic',
'location',
'password',
'is_e'
];
protected $hidden = [
'password', 'remember_token',
];
public function project() {
return $this->hasMany('App\Project');
}
}
我也试过不使用 like 但后来它工作正常。但根本不喜欢工作。请帮忙
谢谢
您必须附加 %
值而不是 LIKE
字符串。试试下面的代码:
User::where('first_name', 'LIKE', $name."%"); // add % with $name
对于双方的匹配字符串
User::where('first_name', 'LIKE', "%".$name."%");
User::where('first_name', 'LIKE', $name."%")->get();
我试图在 laravel 中进行搜索,但在 laravel 中使用
User::where('first_name', 'LIKE %', $name);
没用。 这是我的用户模型。
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable {
use Notifiable;
protected $table = 'users';
protected $fillable = [
'first_name',
'last_name',
'email',
'bio',
'pic',
'location',
'password',
'is_e'
];
protected $hidden = [
'password', 'remember_token',
];
public function project() {
return $this->hasMany('App\Project');
}
}
我也试过不使用 like 但后来它工作正常。但根本不喜欢工作。请帮忙 谢谢
您必须附加 %
值而不是 LIKE
字符串。试试下面的代码:
User::where('first_name', 'LIKE', $name."%"); // add % with $name
对于双方的匹配字符串
User::where('first_name', 'LIKE', "%".$name."%");
User::where('first_name', 'LIKE', $name."%")->get();