Answer the question
In order to leave comments, you need to log in
Why is double return needed when using $this in a Laravel controller?
I'm trying to use $this-> in Laravel controllers. So far, I just understand why they are needed. Like, instead of one long logic in one method, you can divide it into small ones, spawn many methods (and methods in classes and controllers) and then connect the desired method through $this->. Of course, if I imagine everything correctly (I'm a beginner :)). So. I'm redirecting to /home. In the index method, I define the user type and call the client() method:
public function index()
{
$user = User::where('id', Auth::id())
->firstOrFail();
$type = $user->type;
if ($type == 10) {
return $this->client();
}
}
public function client()
{
return redirect('/clients');
}
Answer the question
In order to leave comments, you need to log in
Each function or method is responsible for its own return.
function client() - returns its
own function index() - returns its own
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question