Ravi_R
Ravi_R

Reputation: 187

In Laravel 5, How to customize Session flash message with href

I'm showing Please verify your email before login in my login blade if user didn't verify his account through email link.

if ($user->is_verified == 0) {
    $request->session()->flash("failed", "Please verify your email before login );
    return redirect('/login');
}

And in my blade I do like this to catch it

@if (Session::has('failed'))
    <div class="alert alert-danger">
    {{Session::get('failed')}}.<br><br>
    </div>              
@endif

But Now I have to add this message Please verify your email before login or resend the verification email and make resend part with href to a route. Any ideas ?

Upvotes: 0

Views: 2580

Answers (2)

Ravi_R
Ravi_R

Reputation: 187

Finally I come up with this little changes to the codes.

My code in blade should change like this. Because otherwise it won't accept html syntax, just showing plan html. this is called laravel escape html.

@if (Session::has('failed'))
     <div class="alert alert-danger">
     {!!Session::get('failed')!!}.<br><br>
     </div>
@endif

Md. Sahadat Hossain answer is correct. But accourding my issue I change his code like this.

if ($user->is_verified == 0) {                    
     $msg = 'Please verify your email before login or <a href="'. url("/resend_email").'">resend</a> the verification email';
     $request->session()->flash("failed",  $msg);
     return redirect('/login');
 }

and now it's showing like this as wht I want

enter image description here

Upvotes: 2

Md. Sahadat Hossain
Md. Sahadat Hossain

Reputation: 3236

Use this code

In route.php add a route

Route::get('/resend_mail', 'VerificationMailController@resend'); //replace with your desired location

In VerificationMailController.php

public function resend(){
     //do your resend verification mail code
}

Than use this code where you want to show resend message

if ($user->is_verified == 0) {
$resendurl = route('resend_mail'); //here replace the route of your email verification send route.
$msg = 'Please verify your email before login or <a href="'.$resendurl.'">resend</a> the verification email';
    $request->session()->flash("failed",  $msg);
    return redirect('/login');
}

Upvotes: 1

Related Questions