Y
Y
Yuri Kulaxyz2019-03-28 19:26:15
Laravel
Yuri Kulaxyz, 2019-03-28 19:26:15

How to implement a redirect to the profile filling page during the first user authorization?

There is an idea in the database to add the firts_time field and set it to 1 by default. Then, at the entrance, check this field and redirect to fill out the profile, then change the value from 1 to 0 after the first authorization. But I don’t understand where exactly to organize this check, in middleware or somehow through service providers. I did not find a normal solution on the forums, although the question seems to be popular. I would be grateful for a template solution in such a situation, I am not so strong in Laravel yet.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jazzus, 2019-03-28
@Kulaxyz

Create relation profile hasOne type (if the profile is in a separate table)

public function profile()
{
 return $this->hasOne('App\Models\Profile','user_id', 'id');
}

create middelware hasProfile
write there
if (!Auth::user()->profile) {
    return redirect()->route('profile');
}
return $next($request);

add to routes
Route::group('middleware' => ['verified','hasProfile'], function () {

});

N
NubasLol, 2019-03-29
@NubasLol

protected $redirectTo = '/';
There is such a variable in the controller for registration

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question