A
A
Artem2020-06-08 21:47:16
Laravel
Artem, 2020-06-08 21:47:16

How to fix Undefined variable: e?

when you click the subscribe button:

<a href="{{ route('user.follow', $user->id) }}">Follow</a>

laravel throws error: Undefined variable: e
my route.php:
Route::post('/sn/profile/{profileId}/follow', '[email protected]')->name('user.follow');
Route::post('/sn/profile/{profileId}/unfollow', '[email protected]')->name('user.unfollow');

it doesn’t get to the controller, because I wrote a redirect to the home page there and again I catch this error, but I’ll attach the controller anyway:
public function followUser(int $profileId)
    {
        return redirect()->route('home');
    }

    public function unFollowUser(int $profileId)
    {
        $user = User::where('id', $profileId)->first();
        if(!$user) {
            return redirect()->back();
        }
        $user->followers()->detach(auth()->user()->id);
        return redirect()->back();
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2020-06-08
@artem_atlas

switch ($exception->getStatusCode())

$this->renderHttpException($e)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question