我是 Laravel 的初学者,只是想知道我从表单中保存数据后出了什么问题,它会将我重定向到一个索引页面,这是从一开始就想要的,然后只有我才能查看我的报价详细信息.但是现在我需要的是在添加新报价后,我需要它立即将我重定向到报价详细信息。
return view('bd.quotation.index', compact('quotations'));
这是我把它重定向到引用索引的部分。
redirect('/bd/quotation/{id}'); // type 1
function showQuotation($id) {
return view('bd.quotation.quotationItem', compact('customers','quotations','quotationItems','quotationIT' ));
}
类型 1 我试过了,它不起作用。它会向我显示一个空白页面,而第二个页面无法正常工作。
public function quotationItem($id)
{
$quotations= Quotation::where('id', $id)->first();
$customers = Customer::where('id', $quotations->cust_id)->first();
$quotationIT = QuotationIT::where('quotation_number', $quotations->item_name)->first();
$quotationItems = QuotationItem::where('quotation_number', $id)->get();
return view('bd.quotation.quotationItem', compact('customers','quotations','quotationItems','quotationIT' ));
}
这是我可以查看报价详情的代码。
答案 0 :(得分:0)
我认为你的问题是你没有返回重定向
所以改变:redirect('/bd/quotation/{id}');
到return redirect('/bd/quotation/{id}');
重定向有 3 个步骤:
1- 是在保存数据后在控制器中返回重定向功能:
return redirect('your-url');
在 web.php 中 2-make 路由:
Route::get('your-url', 'YourController@yourFunction');
3-编写你的函数:
public function yourFunction()
{
return "you are here";
}
答案 1 :(得分:0)
试试这个用 id 重定向,我想这种方式会帮助你
return redirect()->route('a_newsEvents',['id'=>$id]);