无法检索从控制器传递的值。 Laravel
Cannot retrieve value passed from controller. Laravel
我无法将值从控制器传递到我的下一个控制器。
我使用了以下代码:
在 BillController 中:
return redirect('pdf')->with($sid);
在路线中:
Route::get('pdf', 'PdfController@invoice');
在我的 PdfController 中:
class PdfController extends Controller
{
public function invoice()
{
$student = Student::where('id',$sid)->first();
foreach ($student->fees as $fee) {
$fees= $fee;
}
}
}
这里有什么问题?谁能帮帮我?
好的,有多种传递值的方法:
1.会话快讯 (https://laravel.com/docs/5.2/session)
首先,您需要使用重定向设置键和值:
// Method phpdoc - public function with($key, $value = null)
return redirect('pdf')->with('sid', $sid);
您可以通过 \Illuminate\Http\Session 对象访问输入值:
// Have a look at the Session values - dd(Session::all());
$sid = Session::get('sid');
2。表单提交 (https://laravel.com/docs/5.2/requests)
如果您 post 值,您可以通过 Request 对象访问它们
public function invoice(Request $request)
{
$sid = $request->get('sid');
3。通过 URL
routes.php
Route::get('sid/{sid}, 'PdfController@invoice')->name('invoice);
重定向调用(将 $sid 添加到路由中):
return redirect()->route('invoice', [$sid]);
控制器:
要获取值,只需在控制器中询问即可。
public function index($sid)
我无法将值从控制器传递到我的下一个控制器。
我使用了以下代码:
在 BillController 中:
return redirect('pdf')->with($sid);
在路线中:
Route::get('pdf', 'PdfController@invoice');
在我的 PdfController 中:
class PdfController extends Controller
{
public function invoice()
{
$student = Student::where('id',$sid)->first();
foreach ($student->fees as $fee) {
$fees= $fee;
}
}
}
这里有什么问题?谁能帮帮我?
好的,有多种传递值的方法:
1.会话快讯 (https://laravel.com/docs/5.2/session)
首先,您需要使用重定向设置键和值:
// Method phpdoc - public function with($key, $value = null)
return redirect('pdf')->with('sid', $sid);
您可以通过 \Illuminate\Http\Session 对象访问输入值:
// Have a look at the Session values - dd(Session::all());
$sid = Session::get('sid');
2。表单提交 (https://laravel.com/docs/5.2/requests)
如果您 post 值,您可以通过 Request 对象访问它们
public function invoice(Request $request)
{
$sid = $request->get('sid');
3。通过 URL
routes.php
Route::get('sid/{sid}, 'PdfController@invoice')->name('invoice);
重定向调用(将 $sid 添加到路由中):
return redirect()->route('invoice', [$sid]);
控制器: 要获取值,只需在控制器中询问即可。
public function index($sid)