我在laravel中有用户模型
public static function searchScoop($keyword)
{
$users = User::where('username','like','%'.$keyword.'%')->
orwhere('email','like','%'.$keyword.'%')->
orwhere('phone','like','%'.$keyword.'%')->
with('user_permission','user_division')->
get(['id','username','email','phone','division','permission']);
return $users;
}
现在如何使用用户变量获取已删除的结果 我试图把withTrashed - >之后到处都有,但注意到工作..
谢谢
答案 0 :(得分:2)
请尝试withTrashed()
,它只会提供软删除的记录。
public static function searchScoop($keyword)
{
$users = User::withTrashed()
->where('username','like','%'.$keyword.'%')
->orwhere('email','like','%'.$keyword.'%')
->orwhere('phone','like','%'.$keyword.'%')
->with('user_permission','user_division')
->get(['id','username','email','phone','division','permission']);
return $users;
}
答案 1 :(得分:1)
public static function searchScoop($keyword)
{
return User::withTrashed()
->where('username', 'like' ,'%'.$keyword.'%')->
->orwhere('email', 'like' ,'%'.$keyword.'%')->
->orwhere('phone', 'like' ,'%'.$keyword.'%')->
->with('user_permission', 'user_division')->
->get(['id', 'username', 'email', 'phone', 'division', 'permission']);
}