Answers for "laravel where like search"

PHP
5

where like laravel

User::query()
   ->where('name', 'LIKE', "%{$searchTerm}%") 
   ->orWhere('email', 'LIKE', "%{$searchTerm}%") 
   ->get();

reference:
https://freek.dev/1182-searching-models-using-a-where-like-query-in-laravel
Posted by: Guest on December-19-2020
3

laravel eloquent search query 2020

$result = Marriage::where('name','LIKE','%'.$email_or_name.'%')
                ->orWhere('email','LIKE','%'.$email_or_name.'%')
                ->get();
Posted by: Guest on August-31-2020
8

laravel where like

$users = DB::table('users')
                ->where('name', 'like', 'T%')
                ->get();
Posted by: Guest on May-13-2020
2

laravel search function

$users = User::has('posts')->withCount('posts')->orderBy('posts_count')->take(50)->get();

$userIndex = $users->search(function($user) {
    return $user->id === Auth::id();
});
Posted by: Guest on June-15-2021
0

search laravel

relationship
  $user = User::with('Profile')->where('status', 1)->whereHas('Profile', function($q){
    $q->where('gender', 'Male');
})->get();


 $searchText = 'test text';
        Product::with('owner')->where(function($query) use ($searchText)
        {
            $query->where('product_name', 'LIKE', '%' . $searchText . '%');

            $columns = ['product_code', 'place_location', 'remark'];

            foreach ($columns as $column ) {
                $query->orWhere($column, 'LIKE', '%' . $searchText . '%');
            }

            $query->orWhereHas('owner', function($q) use ($searchText) {
                $q->where(function($q) use ($searchText) {
                    $q->where('name', 'LIKE', '%' . $searchText . '%');
                    $q->orWhere('company_name', 'LIKE', '%' . $searchText . '%');
                });
            });

        });


$comments = Comment::query()->orderby('created_at', 'DESC');

if (!empty($id)){
    $comments = $comments->where('id', $request->input('id') );
}

if (!empty($name)){
   $comments = $comments->whereHas('author', function ($query) use ($name) { $query-
     >where('username', 'like', $name.'%'); });
}

  $comment = $comments->paginate(10);


->whereHas('Category', function($query) use($q){

                       $query->where('name', 'LIKE', '%'. $q .'%')

         })->paginate(1)->setPath('');
Posted by: Guest on October-18-2021

Browse Popular Code Answers by Language