jcadima
5/3/2018 - 8:43 PM

Check if parameter exists in request


https://laracasts.com/discuss/channels/laravel/best-way-to-check-if-value-is-sent-in-request?page=1

<?php
// id is an optional parameter that might or might not be passed
// Routes:
Route::get('admin/{id?}','VideoController@index' )->name('videos') ;


// Controller
if ( request()->id ){
    dd(request()->id ) ; 
}

// do something if TRUE
// else
// do something else


// URL:
http://hotvuedemo.test/admin     FALSE
http://hotvuedemo.test/admin/3   TRUE