Php 比如%%不在laravel 5.5中工作
我试图在拉雷维尔进行搜索,但在拉雷维尔,当我使用Php 比如%%不在laravel 5.5中工作,php,laravel,laravel-5.5,Php,Laravel,Laravel 5.5,我试图在拉雷维尔进行搜索,但在拉雷维尔,当我使用 User::where('first_name', 'LIKE %', $name); 它不起作用。 这是我的用户模型 <?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends A
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');
}
}
您必须在%
后面附加值,而不是像字符串那样的。请尝试以下代码:
User::where('first_name', 'LIKE', $name."%"); // add % with $name
用于从两侧匹配字符串
User::where('first_name', 'LIKE', "%".$name."%");
您必须在%
后面附加值,而不是像字符串那样附加值。请尝试以下代码:
User::where('first_name', 'LIKE', $name."%"); // add % with $name
用于从两侧匹配字符串
User::where('first_name', 'LIKE', "%".$name."%");