laravel wherehas with condition

68

public function index()

{

    $name = 'india';

    $users = User::with('country')

                    ->whereHas('country', function (Builder $query) use($name){

                        $query->where('name', 'like', '%'.$name.'%');

                    })

                    ->get()

                    ->toArray();

  

    dd($users);

}
User::select()->whereHas('student', $function($q) {
        $q->where('name', $value)
          ->orWhere('age', $value2);
    });
public function index()

{

    $name = 'india';

  

    $users = User::with('country')

                    ->whereRelation('country', 'name', 'like', '%'.$name.'%')

                    ->get()

                    ->toArray();

  

    dd($users);

}
$query = DB::table('user_ads')
            ->join('ads', 'users_ads.ad_id', '=', 'ads.id')
            ->orderBy($column, $method);

if ($input['search']) {
    $query->where('short_description', $input['search']);
}

if ($input['category']) {
    $query->where('category', $input['category']);
}

$query->join('users', 'users_ads.user_id', '=', 'users.id')
    ->select('ads.id', 'ads.img1', 'ads.short_description', 'ads.category', 'ads.product', 'ads.price', 'users.city')

$result= $query->get();

return $result;

Comments

Submit
0 Comments