I have a middleware group of auth inside that i want to apply another middleware to one specific route in that view that is if the profile is not completed user cant go to any other route until he complete his profile and submit.
More Specifically, middle ware is causing loop on redirect because i have 2 middleware.
i created middleware with laravel php artisan and checking the user if profile is incomplete he should redirect to the profile/edit page but its not even working with just check on incomplete empty companyname.
Middlware
class incompleteProfile
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(empty(Auth::user()->details['companyname'])){
return redirect()->route('profile');
}
return $next($request);
}
}
Routes File
Routes
Route::group(['middleware'=>['auth'] ], function(){
// User Profile
Route::get('/profile/edit', 'UserController@profile')->name('profile')->middleware('incompleteProfile');
Route::post('/profile/edit', 'UserController@editProfile')->name('editProfile');
if(Auth::user()->details['companyname'] == ""){...}
, without the empty(). If companyname is a direct attribute of user you can writeif(Auth::user()->companyname == ""){...}
– Brotzkaapp/Http/kernel.php
(laravel.com/docs/5.5/middleware#registering-middleware) – Brotzka/profile
. Your edit-route should beRoute::match(['post','get'],'/profile/edit','UserController@editProfile')
. In your controller you have to check if current method is post or get and return a view with the edit-form or handle the form-input. – Brotzka