skip to Main Content

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


  1. Chosen as BEST ANSWER

    Looks like it was because I was using an API route.

    I added the following to my Kernel.php, and it resolved the issue.

    'api' => [
       IlluminateSessionMiddlewareStartSession::class,
       //etc
    ],
    

  2. Please check app/Http/Kernel.php

    protected $middlewareGroups = [
        'web' => [
            ...
            IlluminateSessionMiddlewareStartSession::class,
            ...
        ],
    
      ....
    ];
    

    and then try to use quest->session()->flash()function.

    public function updateSalesConsultant(Request $request, $uuid)
    {
        ...
        //Flash::success('Sales Consultant information updated for the lead.');
        $request->session()->flash('success', 'Sales Consultant information updated for the lead.');
        ...
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search