Skip to content

Instantly share code, notes, and snippets.

View elbosp's full-sized avatar

Elbo Shindi Pangestu elbosp

  • Codakarta
  • Yogyakarta, Indonesia
View GitHub Profile
@elbosp
elbosp / search_controller.php
Last active October 18, 2020 05:25
live search with php (laravel framework)
use Illuminate\Database\Eloquent\Builder; // JANGAN LUPA INCLUDE ELOQUENT BUILDER
return view('some_view', [
// LEMPAR QUERY SEARCH SEBELUMNYA
'search' => request()->search,
// MENGGUNAKAN FUNCTION WHEN, CHECK: https://laravel.com/docs/8.x/collections#method-when
// MENGGUNAKAN FUNCTION WHEREHAS, CHECK: https://laravel.com/docs/8.x/eloquent-relationships#querying-relationship-existence
'models' => Model::when(request()->search, function($qwr) {