Home  >  Q&A  >  body text

Laravel 9.x: Redirect user to view success message after registration

I'm trying to return a view with a success message after registering a user, with a link to the login page, but the session message is not passed along with the view.

This is my registred() method

protected function registered(Request $request, $user)
{
    return view('frontend.pages.register-success')->with('message', 'Your registration was successful. Click the button below to login to your account');
}

This is the view page

@extends('frontend.layouts.main')
@section('title', 'Registration successful')
@section('content')
<!-- Main Content -->
<div id="main-content" class="site-main clearfix">

    @if (Session::has('message'))
    <section class="popup">
        <div class="popup-inner">
            <div class="popup-content">
                <div class="img">
                    <img src="assets/img/popup/popup.jpg" alt="Image">
                </div>
                <div class="content text-center">

                    <p class="">{{ Session::get('message') }}</p>

                    <h6 class="heading">REGISTRATION SUCCESSFUL!</h6>

                    <a href="{{ route('login') }}" class="button color-2 login-submit">LOGIN TO YOUR ACCOUNT</a>
                </div>
            </div>
        </div>
    </section>
    @endif

</div><!-- /#main-content -->
@endsection


P粉983021177P粉983021177315 days ago817

reply all(1)I'll reply

  • P粉054616867

    P粉0546168672023-11-13 14:14:40

    We can use the session() global helper instead of Session:

    // flash message create
          session()->flash('message', 'This is a message!'); 
          session()->flash('alert-class', 'alert-danger');

    Get flash messages by keystroke from your blade file

    @if(session()->has('message'))
    
    @endif

    reply
    0
  • Cancelreply