I have created login form and using Auth method for authorizing user with email and password. Login is done be doLogin function in HomeControler
public function doLogin()
{
$rules = array(
'email' => 'required|email', // make sure the email is an actual email
'password' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('login')
->withErrors($validator) // send back all errors to the login form
->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
} else {
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if (Auth::attempt($userdata)) {
$id = Auth::id();
return Redirect::to('panel');
} else {
return Redirect::to('login');
}
}
}
In my routes.php file I have created route to get user by id and before that check if user is logged in.
Route::get('panel/{id}', array('before' => 'auth', function($id)
{
$user=User::find($id);
dd($user);
}));
I have faced 2 problems so far:
– How I can create route with get parameters in doLogin function, so that it redirects user in panel/id/ address?
return Redirect::to('panel')->with('id', $id); is not working!And second problem is that panel/{id} route is checking if user is logged in with 'before' => 'auth', but if I logged in with User id 1 and then opened address panel/2/ it opens the current route. How I can make laravel to check that user id that is logged in mit opens the current route. How I can make laravel to check that user id that is logged in matches the user ID that is requested in route?atches the user ID that is requested in route?