2017-11-26 6 views
1

내가 laravel에서 검색을 만들려고 노력했다뿐만 laravel 작동하지 %%. 이것은 내 사용자 모델입니다.등 laravel 5.5

<?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'); 
} 

} 

나는 비슷한 것을 사용하지 않았지만 제대로 작동했다. 그러나 전혀 같이 일하지 않습니다. 제발 도와주세요 고맙습니다

답변

4

너는 문자열이 아닌 값으로 %을 덧붙여 야합니다. 양쪽

User::where('first_name', 'LIKE', "%".$name."%"); 
1
User::where('first_name', 'LIKE', $name."%")->get(); 
에서 일치하는 문자열을

User::where('first_name', 'LIKE', $name."%"); // add % with $name 

: 다음 코드를 사용해보십시오