Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return view with parameters in laravel

I have a return in my controller like this:

    return view('frontend.bike')->with('message', 'Bike Created');

It directs correctly view, however I want to pass it two variables that are needed. Currently I have it routing via:

Route::get('b/{bikename}/{type?}', ['as' => 'bike', 'uses' => 'FrontendController@bike']);

How can I include a bikename and type to the return to make sure it goes to the correct page.

like image 595
Joe Avatar asked Jul 13 '15 02:07

Joe


1 Answers

you can get those route variable in controller as below in function arguments,

public function bike($bikename, $type = null){

    $type = $type ? $type:'N/A'; //optional
    $message = 'Bike Created';
    return view('frontend.bike', compact('message', 'bikename', 'type'));
}

in views/frontend/bike.blade.php,

{{ $message }}
{{ $bikename }}
{{ $type }}
like image 88
pinkal vansia Avatar answered Nov 01 '22 12:11

pinkal vansia