Vuk Stanković Vuk Stanković - 5 months ago 31
PHP Question

Session not working in Laravel 4

I have a problem with Session that won't persist.

In controller I have a function that loads a article for editing

public function getEdit($id)
{
try {
$news = News::findOrFail($id);
View::share('title', Lang::get('admin.editNews').": ".$news->title);
View::share('news', $news);
$this->layout->content = View::make('news.editNews');
} catch (Exception $e) {
Session::flash('message', Lang::get('admin.noSuchNews'));
Session::flash('notif', 'danger');
return Redirect::to("news");
}
}


And I have another function - index, that should display these flash messages.

public function getIndex()
{
var_dump(Session::get('message'));
}


Session is just not persisting. Not working with
Session::flash
, not working with
Session::put
.

Session::get('message')
is just always
null
.

I guess I should mention that I did application routing like this:

Route::controller('news', 'NewsController');

Answer

Ok, I have fixed this.

Thing is, that I have put into session.php file this

'domain' => '.mydomain.com',

But since app is still in localhost, everything with session was failing even though I wasn't using cookie as my Session driver.

When I changed this to

'domain' => '',

Everything started working

Comments