我使用以下代码将联系人与销售线索关联起来:
public function selectSalesConsultant($uuid)
{
$lead = Lead::where('uuid', $uuid)->firstOrFail();
return view('dealer-contacts.select_consultant')
->with(compact('lead'));
}
public function updateSalesConsultant(Request $request, $uuid)
{
$lead = Lead::where('uuid', $uuid)->firstOrFail();
$lead->update([
'contact_id' => $request->get('contact_id')
]);
Flash::success('Sales Consultant information updated for the lead.');
return to_route('select-sales-consultant', ['uuid' => $uuid]);
}
在我的第二个函数中,在更新销售线索后,我希望显示一条成功消息:
Flash::success('Sales Consultant information updated for the lead.');
return to_route('select-sales-consultant', ['uuid' => $uuid]);
以下是我的看法:
@include('flash::message')
下面是在routes/api.php
中定义路由的方式:
Route::get('/select-sales-consultant/{uuid}', [App\Http\Controllers\LeadController::class, 'selectSalesConsultant'])
->name('select-sales-consultant');
如果我没有重定向,而是执行return view()
,则会显示消息。
正确的方法是什么?我使用的是Laracasts Easy flash notifications
包。
3条答案
按热度按时间xt0899hw1#
尝试将代码更改为:
with方法允许您为单个请求向会话传递数据,这样消息在重定向后将在会话中可用,然后,您可以在视图中显示消息。
希望这能解决你的问题。
vbopmzt12#
看起来是因为我用了API路线。
我将以下代码添加到我的
Kernel.php
中,它解决了这个问题。e5njpo683#
请检查应用程序/Http/内核. php
然后尝试使用
quest->session()->flash()
函数。