Witam. Mam problem z nadaniem uprawnień użytkownikom. Myślę że coś jest z kodem gdyż pojawia się komunikat
'SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from userroles
where (0
= 167 and 1
= 2) limit 1)'
public function logowanie(Request $request)
{
$haslo = $request->input('haslo');
$nick = $request->input('nick');
$user = User::where(['nick'=>$nick])->first();
if ($user && Hash::check($haslo, $user->haslo))
{
$role = Roles::where(['nick' => 'admin'])->first();
$user_role = UserRoles::where([['user_id' => $user->id], ['role_id' => $role->id]])->first();
if ($user_role)
{
Auth::login($user);
return view('users');
}
}
else
{
echo 'Błędne dane!';
}
$this->validate($request, [
'nick' => 'required|max:255',
'haslo' => 'required|max:255',
]);
}
Tabele:
CREATE TABLE `uzytkownicy` (
`id` int(11) NOT NULL,
`nick` varchar(32) NOT NULL,
`haslo` varchar(150) NOT NULL,
`email` varchar(40) NOT NULL,
`_token` varchar(50) NOT NULL,
`role_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
```sql
CREATE TABLE`roles` (
`id` int(11) NOT NULL,
`nick` varchar(60) NOT NULL,
`haslo` varchar(60) NOT NULL,
`email` varchar(60) NOT NULL,
`_token` varchar(105) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `userroles` (
`user_id` int(11) NOT NULL,
`role_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;