Best way to display search results

Published 11 months ago by afonte15

Hello, everyone.

I am trying to figure out if this is the best way to display search results?

 public function search()
        $search = \Request::get('q'); //<-- we use global request to get the param of URI
//            $search = Input::get('search');
        $inventories = Inventory::where('lastName','LIKE','%'.$search.'%')
            -> orwhere('firstName', 'LIKE','%'.$search.'%' )
            -> orwhere('department', 'LIKE','%'.$search.'%' )
            -> orwhere('building', 'LIKE','%'.$search.'%' )
            -> orwhere('room', 'LIKE','%'.$search.'%' )
            -> orwhere('manufacturer', 'LIKE','%'.$search.'%' )
            -> orwhere('device', 'LIKE','%'.$search.'%' )
            -> orwhere('model', 'LIKE','%'.$search.'%' )
            -> orwhere('tag', 'LIKE','%'.$search.'%' )
            -> orwhere('macAddress', 'LIKE','%'.$search.'%' )
            -> orwhere('status', 'LIKE','%'.$search.'%' )
            -> orwhere('notes', 'LIKE','%'.$search.'%' )
        return view('',compact('inventories'));

To display the results I am displaying it by location with the specific location link. So, if I would want to see all the computers located in VH, I click on the VH link on the menu. Is it optimal to do it this way, is it safe from mysql injections? Is there a better way to code the URLs? Is there a way to write it without the ? For example.

<li><a href="">VH</a></li>
<li><a href="">WH</a></li>


Route::get('login', '[email protected]');
Route::post('login', '[email protected]_password');
Route::get('auth/logout', 'Auth\[email protected]');
Route::patch('computers/{inventories}', '[email protected]');
Route::get('computers/search', '[email protected]');
Route::resource('computers', 'InventoriesController');
Route::get('computers/create', '[email protected]');
Route::get('/home', '[email protected]');

Please sign in or create an account to participate in this conversation.