Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get trashed with eloquent model using where and with

I have users model in 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;
}   

now how can i get trashed results with users variable i tried to to put withTrashed -> before where after get everywhere but noting works ..

thank you

like image 258
Awar Pulldozer Avatar asked Mar 11 '23 05:03

Awar Pulldozer


1 Answers

Please try with withTrashed() which will give also the soft deleted records. If you only want soft deleted records use onlyTrashed()

 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;
    }   
like image 198
Arun Code Avatar answered Apr 28 '23 08:04

Arun Code