I have the following code to associate a contact to a lead:
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]);
}
In my second function, after the lead is updated, I’d like to display a success message:
Flash::success('Sales Consultant information updated for the lead.');
return to_route('select-sales-consultant', ['uuid' => $uuid]);
Here is what I have in my view:
@include('flash::message')
Here is how the route is defined inside routes/api.php
:
Route::get('/select-sales-consultant/{uuid}', [AppHttpControllersLeadController::class, 'selectSalesConsultant'])
->name('select-sales-consultant');
Nothing gets displayed. If, instead of redirecting, I do a return view()
, the message does get displayed.
What’s the proper way of doing this? I’m using the Laracasts Easy flash notifications
package.
2
Answers
Looks like it was because I was using an API route.
I added the following to my
Kernel.php
, and it resolved the issue.Please check app/Http/Kernel.php
and then try to use
quest->session()->flash()
function.