Home > Net >  return user to a view with success message after registration laravel 9.x
return user to a view with success message after registration laravel 9.x

Time:07-07

I am trying to return a view with a success message with a link to the login page after registering a user, however the session message isn't passed along with the view.

Here 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');
}

Here is the view page

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

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

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

                    <h6 >REGISTRATION SUCCESSFUL!</h6>

                    <a href="{{ route('login') }}" >LOGIN TO YOUR ACCOUNT</a>
                </div>
            </div>
        </div>
    </section>
    @endif

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

CodePudding user response:

Here you need to pass variable

Change this

@if (isset($message))

And

<p >{{$message}}</p>

CodePudding user response:

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

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

get flash message by key from your blade file

@if(session()->has('message'))
<section >
        <div >
            <div >
                <div >
                    <img src="assets/img/popup/popup.jpg" alt="Image">
                </div>
                <div >

                    <p >{{ session('message') }}</p>

                    <h6 >REGISTRATION SUCCESSFUL!</h6>

                    <a href="{{ route('login') }}" >LOGIN TO YOUR ACCOUNT</a>
                </div>
            </div>
        </div>
    </section>
@endif
  • Related