Answers for "search eloquent laravel"

PHP
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
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
1

search laravel

// Employee Model
public function searchResult($search)
{
  $query = DB::table("employee") ->where('employee_name', 'LIKE', '%'.$search.'%')->get();
  return $query;
}
Posted by: Guest on October-24-2021

Code answers related to "search eloquent laravel"

Browse Popular Code Answers by Language