ako
ako

Reputation: 2126

Laravel does not return data to the view

My Laravel-5.4 project was working fine. but now it's driving me crazy when trying to return data from controller to the view:

Requested url is :

Route::middleware(['web'])->group(function () {
    Route::prefix('service')->group( function () {
        Route::get('{service_slug}', 'ServiceController@findBySlug')->name('service.find_by_slug');
    });
});

Controller action is as below:

function findBySlug ($slug)
{
   return back()->withMessage('test message');
}

Here in the blade view i can not catch $message variable, in fact there is no $message variable in the view.

 @php
 if (isset($message))
   dd($message);
 @endphp

How can i fix it?...thanks.

Upvotes: 2

Views: 466

Answers (1)

lagbox
lagbox

Reputation: 50481

You are redirecting. You are 'flashing' data to the session when you redirect 'with` data like that. You have to get it from the session.

Also there is nothing related to passing something from the controller to a view in your post.

Docs 5.4 - Responses - Redirecting with flashed session data

Upvotes: 3

Related Questions