2

Can someone please tell me why it doesn't works? Returns nothing.

Route:

Route::get('/terms/privacy/', [
    'uses'=>'contentController@dynamic',
    'urlkey'=>'privacy'
])->name('privacy');

ContentController:

public function dynamic($urlkey){
  return $urlkey;
}
Vixed
  • 3,429
  • 5
  • 37
  • 68

2 Answers2

2

You can create fixed routes in Laravel that specifies the parameters from the controller method using defaults. Like this

Route::get('/terms/privacy', ['uses'=>'contentController@dynamic'])->name('privacy')->defaults('urlkey', 'privacy');

You can look this

Alias for a route with a fixed parameter value

rkj
  • 8,067
  • 2
  • 27
  • 33
0

You can define the default value to the function paramter.

Route::get('terms/privacy', function ($urlkey = 'YourValue') {
    return $urlkey;
});
//For Controller function 
public function functionName($urlkey = 'test'){
  return $urlkey;
}

And for the updated version you have default function also

Route::get('/terms/privacy', ['uses'=>'contentController@dynamic'])->name('privacy')->default('urlkey', 'privacy');
DsRaj
  • 2,288
  • 1
  • 16
  • 26