How to display two dynamic names within one url using laravel -
the following code:
{{url('/'.$subjecttype->name)}}
is name 'garden' wrapped in url. gives me localhost/garden garden dynamic name. routes setup so:
route::get('/{subject}/', array( 'as' => 'subject', 'uses' => 'subjectcontroller@getsubject'));
the question how setup 2 dynamic names within 1 route? example
localhost/garden/12
so want route this
route::get('/{subject}/{id}/', array( 'as' => 'subjectid', 'uses' => 'subjectcontroller@getsubjectid'));
but more importantly in view? have of garden header wrapped in url looks this:
'gardening tips beginners' {{$subjecttype->title}}
below poor attempt @ want hope picture.
{{url('/$subjecttype->name/$subjecttype->id/'.$subjecttype->title)}}
thanks
for route:
route::get( '/{subject}/{id}/', array( 'as' => 'subjectid', 'uses' => 'subjectcontroller@getsubjectid' ) );
you can generate url following code:
$url = url::route( 'subjectid', array( 'subject' => $subjecttype->name, 'id' => $subjecttype->id ) );
or, if prefer use helper functions:
$url = route( 'subjectid', array( 'subject' => $subjecttype->name, 'id' => $subjecttype->id ) );
that's going give url http://example.com/subjectname/42
. if want add parameter title @ end of url, you'll need add parameter route definition. if don't you're going 404 errors because no route match url.
Comments
Post a Comment