Summer Sale! All accounts are 50% off this week.

hamzaelmaghari's avatar

Overriding Laravel Fortify

Hello guys!

Do you know what to do in order to override session flush messages in Laravel Fortify? I got an idea to override the default responses myself but I just wanted to know if that's good or not for performance

For example I need session error instead of $session and success instead of $session .

Thanks in advance

0 likes
8 replies
Sinnbeck's avatar

Can you show the related code just so we can see what you want to change?

1 like
hamzaelmaghari's avatar

@Sinnbeck Here is the scenario, a user need to verify his email address, once they do that by default Foritfy throw the session below:

@if (session('status') == 'verification-link-sent')
    <div class="mb-4 font-medium text-sm text-green-600">
        A new email verification link has been emailed to you!
    </div>
@endif

Instead of that user should get success session like below:

@if (session('success'))
    <div class="mb-4 font-medium text-sm text-green-600">
        {{ session('success') }}
    </div>
@endif

This latter comes from https://github.com/laravel/fortify/blob/1.x/src/Http/Responses/VerifyEmailResponse.php

But how it works IDK

hamzaelmaghari's avatar

@Snapey In fact related to Fortify it appears at

            Route::get('/email/verify', [EmailVerificationPromptController::class, '__invoke'])

But, that's not the issue Fortify login, register, forgot password, I want to give all of them a named session which are error, success.

hamzaelmaghari's avatar

@Snapey It doesn't, views are made by the developer which is me. What I want to achieve here is to return a logical feedback if the status is succeeded or not.

This isn't related to views ...

For example look at the section in the docs: https://laravel.com/docs/9.x/fortify#resending-email-verification-links

Here we have the following:

@if (session('status') == 'verification-link-sent')
    <div class="mb-4 font-medium text-sm text-green-600">
        A new email verification link has been emailed to you!
    </div>
@endif

But what if we want make a global session:

@if (session('success'))
    <div class="mb-4 font-medium text-sm text-green-600">
{{ session('success') }}
    </div>
@endif
// if failed should be
@if (session('error'))
    <div class="mb-4 font-medium text-sm text-green-600">
{{ session('error') }}
    </div>
@endif

NB: I don't use views but, using vue.js

1 like
martinbean's avatar

@hamzaelmaghari Why do you need to change them? You just need to use the correct keys in your views; not change the keys themselves that is set by a package.

1 like
hamzaelmaghari's avatar

@martinbean Yes, unfortunately Laravel doesn't give the ability to do that, please re-read my previous comment.

In my daily coding life I prefer to use a global response wich is like:

return back()->with('success', 'User saved!');

What ever the message is it would be echoed as:

@if(session('success'))
{{ session('success') }}
@endif

So I don't have to specify everytime the message like fortify does:

@if (session('status') == 'two-factor-authentication-enabled')
    <div class="mb-4 font-medium text-sm">
        Please finish configuring two factor authentication below.
    </div>
@endif
1 like

Please or to participate in this conversation.