Route :
Route::get('merchantTrans/{id}','MerchantController@merchant');
Merchant Controller :
public function merchant($id){
$merchant = Merchant::whereId($id)->get();
return redirect('Merchant view')->with(compact('merchant'));
}
View Route :
Route::view('Merchant view','merchant.listview')->name('Merchant view');
I cannot pass merchant compact value to view.
Produce error
Any other best way?
Redirection with the Flashed Session Data in Laravel framework. 1. Redirection to the URL within Laravel. return redirect ('user/dashboard'); 2. Redirection back to the previous page within Laravel. return redirect ()->back (); OR. return redirect ()->back ()->withInput ();
Laravel provides different ways to pass data to a view. We can pass data directly from routes or through the controller. Here are some of the ways we can pass data to the view: 1. Using view (): We can directly pass the data in the ‘ view () ’ helper function by using the second parameter in the function which takes an array as key and value pair.
Since you want to pass dynamic parameters then it will be better to use the regular route passing by the related controller action and retrieving the desired data. Show activity on this post. The variable name (user_detail) should be same as the name in compact. Right syntax for laravel 5.4 and heigher versions.
Being open-sourced itself, the laravel framework allows third-party programs to be integrated into their command lines. This is also the reason why developers prefer to use the laravel framework to create vast systems. Let us have a look a few examples to understand how does the laravel redirect to URL work:
Try this
return redirect()->route('Merchant view')->with( ['merchant' => $merchant] );
In blade file :
<?php $merchants = Session::get('merchant'); ?>
@foreach ($merchants as $merchant)
//your code
@endforeach
Hope it helps you !
The Route::view
is made for the static views with static parameters passed like :
Route::view('Merchant view','merchant.listview', ['param1' => 'value1']);
Since you want to pass dynamic parameters then it will be better to use the regular route passing by the related controller action
and retrieving the desired data.
Anyway you could use Redirect::route()
like :
return Redirect::route('Merchant view',['merchant' => base64_encode($merchant)]);
And get the passed variable in the blade side as a HTTP parameter using :
{{ base64_decode(Request::get('merchant')) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With