问题描述
我有一个名为index.blade.php的视图,该视图显示有关供应商的信息,该信息是通过控制器传递的,例如VendorController,在此视图上,我有一个查看地址"按钮,现在我想在单击按钮时显示此供应商的数据.我还有另一个控制器,即VendorAddressController,它从数据库中获取供应商的地址. index.blade.php文件的代码:
I have a view named index.blade.php which shows information about a vendor, which was passed through a Controller e.g. VendorController, on this view I have a button "View address", now I want to display the data of this vendor on button click. I also have another controller namely VendorAddressController which fetches the address of the vendor from the db. Code of index.blade.php file :
<td>
<a href="{!! $vendor->slug !!}/vendor-address/" class="btn btn-primary">View Address</a>
</td>
在VendorAddressContoller中
in VendorAddressContoller
public function index($id)
{
$vendor = Vendors::find($id);
$vendorsaddress = VendorAddress::where('vendor_id', $vendor->id)->paginate(15);
return view('admin.vendoraddress.index',['vendorsaddress'=>$vendorsaddress, 'vendor'=>$vendor, 'address'=>$address]);
}
但是当我单击按钮时,什么都没出现
But when i click on button nothing is coming
推荐答案
有多种方法可以做到这一点.您可以根据需要选择多种选择.
There is a multiple way to do that. You can choose one the many choice as per your requirement.
1..通过会话
您可以在第一个控制器中完成
You can do this in the first controller
Session::put('key', 'value');
然后在第二个
Session::get('key');
2..通过Cookie 您的第一个控制器:
2. By CookiesYour first controller:
$response = Response::make('Hello World');
return $response->withCookie(Cookie::make('name', 'value', $minutes));
并在下一个请求中获取它
And get it in the next request
$value = Cookie::get('name');
您可以在此处.
这篇关于如何在Laravel中将变量从一个控制器传递到另一个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!