Ответы пользователя по тегу Laravel
  • При редиректе не подгружает контент?

    @bubaley
    Первым параметром функции route() необходимо указывать именованный маршрут. Я так понимаю вы пытаетесь оттдать view. Попробуйте передать url.
    https://laravel.ru/docs/v5/redirects
    https://laravel.com/docs/7.x/redirects#redirecting...
    Ответ написан
    Комментировать
  • Проверка, запрос в базу при авторизации в laravel?

    @bubaley
    Здравствуйте, вы можете переопределить сам механизм авторизации, методом login
    Или уже отработать успешную авторизацию.
    Это необходимо добавить в Auth/LoginController
    Конечно лучше зайти в сам контроллер от которого наследуется LoginController и скопировать оттуда, чтобы быть привязанным к своей версии Лары.
    public​ ​function​ ​login​(​Request​ ​$request​)​
    ​    {​
    ​        ​if​ (​isset​(​$request​->​next​)) ​$this​->​redirectTo​ ​=​ ​$request​->​next​;​
    ​
    ​        ​$this​->​validateLogin(​$request​);​
    ​
    ​        ​//​ If the class is using the ThrottlesLogins trait, we can automatically throttle​
    ​        ​//​ the login attempts for this application. We'll key this by the username and​
    ​        ​//​ the IP address of the client making these requests into this application.​
    ​        ​if​ (​method_exists​(​$this​, ​'​hasTooManyLoginAttempts​'​) ​&&​
    ​            ​$this​->​hasTooManyLoginAttempts(​$request​)) {​
    ​            ​$this​->​fireLockoutEvent(​$request​);​
    ​
    ​            ​return​ ​$this​->​sendLockoutResponse(​$request​);​
    ​        }​
    ​
    ​        ​if​ (​$this​->​attemptLogin(​$request​)) {​
    ​            ​return​ ​$this​->​sendLoginResponse(​$request​);​
    ​        }​
    ​
    ​        ​//​ If the login attempt was unsuccessful we will increment the number of attempts​
    ​        ​//​ to login and redirect the user back to the login form. Of course, when this​
    ​        ​//​ user surpasses their maximum number of attempts they will get locked out.​
    ​        ​$this​->​incrementLoginAttempts(​$request​);​
    ​
    ​        ​return​ ​$this​->​sendFailedLoginResponse(​$request​);​
    ​    }​
    ​
    ​    ​/**​
    ​     * The user has been authenticated.​
    ​     *​
    ​     * ​@param​  \Illuminate\Http\Request  $request​
    ​     * ​@param​  mixed  $user​
    ​     * ​@return​ mixed​
    ​     ​*/​
    ​    ​protected​ ​function​ ​authenticated​(​Request​ ​$request​, ​$user​)​
    ​    {​
    ​        ​return​ response([​
    ​            ​'​result​'​ ​=>​ ​'​success​'​,​
    ​            ​'​value​'​ ​=>​ ​$user​
    ​        ]);​
    ​    }​
    ​
    ​    ​/**​
    ​     * Get the failed login response instance.​
    ​     *​
    ​     * ​@param​  \Illuminate\Http\Request  $request​
    ​     * ​@return​ \Symfony\Component\HttpFoundation\Response​
    ​     *​
    ​     * ​@throws​ \Illuminate\Validation\ValidationException​
    ​     ​*/​
    ​    ​protected​ ​function​ ​sendFailedLoginResponse​(​Request​ ​$request​)​
    ​    {​
    ​        ​return​ response([​
    ​            ​'​result​'​ ​=>​ ​'​fail​'​,​
    ​            ​'​value​'​ ​=>​ ​'​Неверный логин или пароль​'​
    ​        ]);​
    ​    }​
    Ответ написан
    1 комментарий
  • Как добавить свои роуты в laravel после авторизации?

    @bubaley
    Можно написать свой middleware и повесить его на динамический роут.
    В этом middleware получать пользователя и проверять его на доступ.
    Ответ написан
    1 комментарий