Coder Social home page Coder Social logo

Redirection customization about fortify HOT 17 CLOSED

laravel avatar laravel commented on April 28, 2024 52
Redirection customization

from fortify.

Comments (17)

nadhifikbarw avatar nadhifikbarw commented on April 28, 2024 52

Here's a simple workaround if you need to implement it right now. However I would too absolutely prefer much more cleaner solution, such as adding new dedicated config key would be the easiest implementation, but for now this should do.


Add new config key in config/fortify.php

'registered' => '/onboarding',

or you could also make it use RouteServiceProvider const

// app/providers/RouteServiceProvider.php
public const REGISTERED_REDIRECT = '/onboarding'


// app/config/fortify.php
'registered' => App\Provider\RouteServiceProvider::REGISTERED_REDIRECT,

Create new class App\Responses\RegisterResponse

<?php

namespace App\Responses;

use Illuminate\Http\Response;
use Laravel\Fortify\Contracts\RegisterResponse as RegisterResponseContract;

class RegisterResponse implements RegisterResponseContract
{
    public function toResponse($request)
    {
        return $request->wantsJson()
            ? new Response('', 201)
            : redirect(config('fortify.registered'));
    }
}

Bind new interface implementation inside FortifyServiceProvider.php

use App\Responses\RegisterResponse;
use Laravel\Fortify\Contracts\RegisterResponse as RegisterResponseContract;

/**
* Register any application services.
*
* @return void
*/
public function register()
{
    $this->app->bind(
        RegisterResponseContract::class,
        RegisterResponse::class
    );
}

from fortify.

rafayrty avatar rafayrty commented on April 28, 2024 48

Hi There Add This To The Route File It Should Work.

Route::get('/login',function(){
    return redirect()->route('index');
})->name('login');

from fortify.

fantomas-code avatar fantomas-code commented on April 28, 2024 10

Ya lo solucione ....
en el archivo RouteServiceProvider.php escribi esta linea

Captura de pantalla (12)

public const LOGOUT_REDIRECT = '/login'; <------ que redirecciona al login

luego en el archivo fortify.php la mande a llamar con el nombre 'salir'

Captura de pantalla (14)

luego cree una carpeta llamada Responses dentro de la carpeta app. Ahí cree un archivo llamado LogoutResponse.php y en ese archivo mande a llamar a la constante (no me queda claro si es constante o variable) con el nombre salir

Captura de pantalla (17)

from fortify.

jonasvanderhaegen avatar jonasvanderhaegen commented on April 28, 2024 5

Using Laravel v8.9.0, On top of RouteServiceProvider:

/**
 * The path to the "home" route for your application.
 *
 * This is used by Laravel authentication to redirect users after login.
 *
 * @var string
 */
public const HOME = '/';

from fortify.

taylorotwell avatar taylorotwell commented on April 28, 2024 3

Feel free to send a PR.

from fortify.

sambindoff avatar sambindoff commented on April 28, 2024 1

@c0nst4ntin that's exactly what @nadhifikbarw's suggestion above accomplishes, simply create a response class and bind this to the container as the Fortify register response.

from fortify.

fantomas-code avatar fantomas-code commented on April 28, 2024 1

Hello, I would like to know how I can do to customize the redirection after logging out.
I see that by default it redirects you to the index of your project, I don't like that .. please help

from fortify.

jimgwhit avatar jimgwhit commented on April 28, 2024 1

Custom redirection has been handled, see https://laracasts.com/discuss/channels/laravel/version-8-redirects

That was resolved immediately when laravel version 8 came out.

from fortify.

Adhik13th avatar Adhik13th commented on April 28, 2024

i think its not like that

from fortify.

joshmorel avatar joshmorel commented on April 28, 2024

@jonasvanderhaegen this is okay for certain use cases. But imagine I wanted to customize further, e.g. redirect to a variable path after profile update (imagine -> profile/MyNewUserName)

from fortify.

mrpritchett avatar mrpritchett commented on April 28, 2024

+1 for this feature request

from fortify.

c0nst4ntin avatar c0nst4ntin commented on April 28, 2024

I'm not too familiar with this, but couldn't publishing single response classes or controllers and then having the possibility to overwrite these work? If so, is there a way?

from fortify.

nadhifikbarw avatar nadhifikbarw commented on April 28, 2024

@betopicapiedra You could use the same method like my previous suggestion, but instead of rebinding the RegisterResponse contract, rebind the LogoutResponse contract instead.

from fortify.

fantomas-code avatar fantomas-code commented on April 28, 2024

I already did what you suggested but it doesn't work
@nadhifikbarw

from fortify.

victoralbino avatar victoralbino commented on April 28, 2024

In the pull request implemented the possibility to perform some action after the user registers
Now it is only necessary to implement the afterRegister() method in the App\Actions\Fortify\CreatesNewUsers Class and what is in it will be executed after registration.

from fortify.

nadhifikbarw avatar nadhifikbarw commented on April 28, 2024

@betopicapiedra Please use English so it's easier for everyone, but assuming from your screenshot, you haven't bind your LogoutResponse implementation with LogoutResponseContract via FortifyServiceProvider

from fortify.

fantomas-code avatar fantomas-code commented on April 28, 2024

Ya esta solucionado ....gracias ...

It is already resolved, thank you ...

from fortify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.