php - what is the difference between return redirect('/') and Redirect::to('/')->send(); function in laravel

First code working. See Below

The second code not working. See Below

Anyone can help provide the documentation for this code Redirect::to('/')->send();

Answer

Solution:

The ->send() method should only be used in places where you cannot return a response directly. And even then, it should be used as few times as possible.

Normally, a request will go through a list of middlewares, end up in a controller which will return a response and exit through another list of middlewares. This is the normal way of returning a response.

When you use the send() function, you interrupt the pipeline and send the response back immediately.

Now, the reason only send() works in your case is because you are redirecting from a constructor and a constructor cannot have a return value. Because of this, the second example will never work.

I would encourage you to use a middleware for this check instead. This way the check is reusable and you can return a redirect response without interrupting the pipeline.

Source