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('');