In Laravel 6.x, how do I get optional parameters to my controller? For example, my route:
Route::get('/videos/{limit?}/{channel?}, VideosController@index);
And in my VideosController I have a method:
public function index($limit=20, $channel=null)
{
if (!is_null($channel))
{
$channel_id = channel::where('name', $channel);
$result =
<some complicated DB query>
->where('channel_id', $channel_id)
->limit($limit)
->first();
} else {
$result =
<some complicated DB query>
->limit($limit)
}
}
But for some reason I never seem to fall into the !is_null($channel)
case.