Part 13 – Sessions & Flash Messages [How to Build a Blog with Laravel 5 Series]



—- UPDATE, PLEASE READ IF YOU ARE HAVING ISSUES —
This tutorial was created using Laravel 5.2.15. Newer versions of Laravel from 5.2.25 and later automatically include web middleware by default for all routes. This means that you do not need to add the Route::group() like I do in this video. It is added to all routes automatically in any version of Laravel after 5.2.25. If you created your Laravel app in April 2016 or later, you likely have a newer version of Laravel and you DO NOT NEED TO ADD WEB MIDDLEWARE ANYMORE. In fact adding it now, creates a broken loop and causes middleware to break and for your flash messages to not work.

If you’re routes.php page doesn’t have the empty Route::group at the bottom like mine did in the video that it means you are using a newer version of Laravel with the web middleware added by default. This is a good sign that you can skip this step. Please remember to skip this step in future videos as well.

This will also apply to any future reference I make in later videos in this series where I have “web” middleware. If you have a recent download of Laravel then you can kindly ignore this advice in my video. Your version of Laravel will have this middleware built in for all routes automatically. Please do not add it like I tell you to do in this video.

—————————

Before we move on, we need to set up messages for our application. Since we are adding and removing things from the database now we will find ourselves in many situations where we need to start giving feedback to our users. You have seen these on other websites before, when you get a success or error message when things go right or wrong.

Before we set up messages we have to first understand Sessions. Sessions are temporary ways of storing information for a user that needs to persist along multiple requests, but does not need to be permanently stored. Flash messages are a small subset of Sessions and these include data that is part of the next request but will be deleted after. So flashed session variables only exist for one request.

This makes them perfect for storing messages because most messages only need to be displayed once and then can be forgotten or deleted.

— CODE —

To create a session
Session::put(‘key’, ‘value’);

To create a flash session
Session::flash(‘key’, ‘value’);

— DOWNLOAD SOURCE CODE —

https://github.com/jacurtis/laravel-blog-tutorial/blob/part_13/app/Http/routes.php

— LINKS —

getbootstrap.com/components/#alerts

— MORE FROM THIS SERIES —
Previous Video [Part 12]: https://youtu.be/5j3fgiaSK4E
Previous (optional) Video [Part 12½]: https://youtu.be/JmvHTg0sy6o
Next video [Part 14]: https://youtu.be/0Qzi1yOoLBQ

Full Playlist for the “How to Build a Blog with Laravel” Series: https://www.youtube.com/playlist?list…

— FOLLOW ME —

Subscribe for New Releases!

Twitter – http://twitter.com/_jacurtis
(ask me questions!)

— QUESTIONS? —

Leave a comment below and I or someone else can help you.
For quick questions you may also want to ask me on Twitter, I respond almost immedietely.

You can also email me: hello@jacurtis.com

Thanks for all your support!

Tags: Messages and Flash messages in Laravel using sessions. Sessions are easy to learn. Laravel 5.2 Framework Tutorial Easy to learn. Best tut about Laravel. Build a blog with Laravel Tutorial. Beginner tutorial. How to video. PHP framework easy best tutorial. Laravel 5 coding in PHP with Alex.

source

Reply

Do NOT follow this link or you will be banned from the site!