C
C
Cavin March2017-01-13 22:55:55
Laravel
Cavin March, 2017-01-13 22:55:55

How to intercept all url requests in Laravel?

Good day. The task is this: when a person goes to any page of the site, you need to check him for authorization, and if he is not authorized, then send him to the authorization page, I thought to do everything through Route:: get ... But apparently this will not work, in general prompt in what direction to dig?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
Cavin March, 2017-01-14
@ForbsmC

In short, I solved everything this way: I
created a 404 page by changing the 'render' function along the app/Exceptions/Handler.php path and wrapped all the necessary links in a group, as suggested earlier. Thanks for the help, good luck to everyone :)
If anyone needs it, keep the function:

public function render($request, Exception $e)
    {
        //customize 404 page
        if ($this->isHttpException($e)) {

            $statusCode = $e->getStatusCode();

            switch ($statusCode) {
                case '404':
                    //Страница берется из директории resources/views
                    return response()->view('notfound');
            }
        }
        return parent::render($request, $e);
    }

Source: https://laravel.ru/forum/viewtopic.php?id=1470

A
Andrzej Wielski, 2017-01-13
@wielski

Route::group(['middleware' => ['auth']], function() {
  // тут все ваши роуты
});

A
Alexander Aksentiev, 2017-01-13
@Sanasol

Kernel.php
add a middleware to the web group.

H
honormgr, 2017-01-14
@honormgr

It is not necessary to crutch, MiddleWare for whom have thought up? You make a condition, add it to the Kernel, make a Route with a group of the middleware you created and cheers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question