samedi 5 mars 2016

Laravel flash message stays on page for more than one request

Ok, so I'm currently building a blog at the moment, and on my add post page (the dashboard) I'm flashing a message with Javascript sweetalert and that works fine, but I'm including a link inside that to view the post you just wrote. When you click on it, and press the back button, the flash message shows again. And again. And again forever.

Here's my add post action in the controller:

public function createBlogPost(Post $post, Request $request)
{
    $post = new Post;

    $post->title = $request->title;
    $post->slug = str_slug($post->title, '-');
    $post->thumbnail = $request->thumbnail;
    $post->content = $request->content;
    $post->save();

    $mostrecent = DB::table('posts')->orderBy('created_at', 'desc')->first();
    $mslug = $mostrecent->slug;
    $request->session()->put('mslug', $mslug);

    Session::flash('post_success', 'post success');
    return redirect('admin/dashboard');
    // I have tried Session::forget('post_success');
    //              Session::pull('post_success');
    //              Session::flush();
}

I really don't know what the problem is, but I'm fairly sure it must be to do with the redirect, as I can forget the key before redirecting and the message won't be flashed.

Any help would be greatly appreciated

( Ignore the bad PHP, I'm still pretty new to this stuff :P )



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TWUBaC
via IFTTT

Aucun commentaire:

Enregistrer un commentaire