Я сделал запрос и получил коллекцию из 11 массивов объектов БД.В основном 11 постов.Мне нужно выполнить поиск по шаблону, если в каком-либо из этих сообщений есть строка (в заголовке, модели или описании).Как лучше всего этого добиться?Я пробовал с несколькими orWhere, но, похоже, не работает.
Моя функция
public function search(Request $request)
{
$this->validate($request, [
'search' => 'required',
'country' => 'required',
]);
$search=$request->input('search');
$posts = Country::where('country_name', $request->input('country'))->first()->posts;
$customers=$posts::where('title','LIKE','%'.$request->search.'%')
->orWhere('model','LIKE','%'.$request->search.'%')
->orWhere('notes','LIKE','%'.$request->search.'%')
->orWhere('description','LIKE','%'.$request->search.'%')
->get();
dd($posts);
}
$ сообщений - ответ
Collection {#367 ▼
#items: array:11 [▼
0 => Post {#368 ▼
#table: "posts"
#dates: array:1 [▶]
#fillable: array:18 [▶]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:22 [▼
"id" => 1
"title" => "Brand New Harley Davidson For Sale"
"make_id" => "1"
"model" => "Sportster"
"year" => 2019
"price" => "987890.00"
"mileage" => 8798
"mileage_unit" => "KM"
"negotiable" => "negotiable"
"condition" => "All Good"
"plate" => null
"vin" => null
"color" => null
"notes" => null
"description" => null
"created_by" => 1
"status_change" => "2019-06-12 02:35:51"
"status" => "Deleted"
"slug" => "1560305498-Brand-New-Harley-Davidson-For-Sale"
"created_at" => "2019-06-12 02:11:38"
"updated_at" => "2019-06-12 02:36:50"
"laravel_through_key" => "IND"
]
#original: array:22 [▶]
#changes: []
#casts: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
1 => Post {#369 ▶}
2 => Post {#370 ▶}
3 => Post {#371 ▶}
4 => Post {#372 ▶}
5 => Post {#373 ▶}
6 => Post {#374 ▶}
7 => Post {#375 ▶}
8 => Post {#376 ▶}
9 => Post {#377 ▶}
10 => Post {#378 ▶}
]
}