[英]LIKE %% not working in laravel 5.5
I was trying to make a search in laravel but in laravel when I used 我试图在laravel中进行搜索,但是当我使用laravel时
User::where('first_name', 'LIKE %', $name);
It Didn't work. 没用 This is my user model. 这是我的用户模型。
<?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');
}
}
I also tried not using like but then it was working properly. 我也尝试过不使用like,但是它可以正常工作。 But not working at all with like. 但是根本不喜欢。 please help thanx 请帮助thanx
You have to append %
with value not with LIKE
string. 您必须在%
后面附加值,而不是LIKE
字符串。 Try following code: 尝试以下代码:
User::where('first_name', 'LIKE', $name."%"); // add % with $name
For match string from both side 从两侧匹配字符串
User::where('first_name', 'LIKE', "%".$name."%");
User::where('first_name', 'LIKE', $name."%")->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.