Laravel Spark - redirection at login

I have a very simple problem. I just want to direct the user to a place other than "/ home" after logging in. It is not difficult if you can change the spark software and save these changes in every deployment. However, the composer re-installs everything when something is being deployed, and usually the wrong practice is to make changes to the software of the main provider.

This seems to be a very simple and easy way for creators to work in software. So how do I do this?

I tried...

Changing the redirectTo and redirectPath variables in the auth controller and password controller in my application.

Adding a login controller to my application - regardless of the spark - and then resetting the same variables.

Attempted to call the afterLoginRedirectTo and afterAuthRedirectTo functions in a Spark service provider. This returned an error indicating that no functions exist.

Not sure where to go from here.

+4
source share
1 answer

After the same problem, I did something, and found a way to install something other than home, I changed a few things, but hopefully this works for you too!

TL; DR

Spark::afterLoginRedirectTo('somenewplace');

Option 1

Variable used: $afterLoginRedirectTofrom provider \ laravel \ spark \ src \ Configuration \ ManagesAppOptions.php

You can set this in the SparkServiceProvider @ boot method:

Spark::afterLoginRedirectTo('somenewplace');

Spark LoginController\vendor\laravel\spark\src\Http\Controllers\Auth\LoginController.php

:

 if (Spark::usesTwoFactorAuth() && $user->uses_two_factor_auth) {
        return $this->redirectForTwoFactorAuth($request, $user);
    }

    return redirect()->intended($this->redirectPath());

RedirectPath() - RedirectsUsers, :

return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';

redirectTo LoginController :

$this->redirectTo = Spark::afterLoginRedirect();

2

, .

web.php :

Route::post('/login', 'Auth\NewLoginController@login');

LoginController :

 class LoginController extends \Laravel\Spark\Http\Controllers\Auth\LoginController
 {
   public function authenticated(Request $request, $user)
   {
    /**
     * @var $user User
     * Set some logic here of your own for new redirect location
     */
    if ($user->last_page_accessed != null) {
      $this->redirectTo = $user->last_page_accessed;
    }
    return parent::authenticated($request, $user);
  }
}
+6

Source: https://habr.com/ru/post/1667509/


All Articles