laravel jak to zrobić za pmoca ról

0

Mam taki problem zawsze w laravelu nie używałem ról

czyli jak sprawdzałem czy użytkownik ma dostęp do kontrolera to w kontrolerze używałem
if (warunek) {
akcja
}

natomiast mam teraz takie coś, że mam akcje dla użytkoniwków i mam akcje dla innych użytkowników którzy nie są użytkiwnikami, ale jak wpiszą nazwę użytkownika i hash to może przeglądać zawartość tego co może np użytlkownik tomi, ale nie może modyfikować ani dodawać

tabela wygląda tak

idPodstawowy 	bigint(20) 		UNSIGNED 	Nie 	Brak 		AUTO_INCREMENT 	Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	2 	loginIndeks 	varchar(255) 	utf8mb4_unicode_ci 		Nie 	Brak 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	3 	emailIndeks 	varchar(255) 	utf8mb4_unicode_ci 		Nie 	Brak 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	4 	email_verified_at 	timestamp 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	5 	password 	varchar(255) 	utf8mb4_unicode_ci 		Nie 	Brak 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	6 	start_day 	tinyint(4) 			Nie 	0 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	7 	minutes 	smallint(6) 			Nie 	60 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	8 	level_mood_10 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	9 	level_mood_9 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	10 	level_mood_8 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	11 	level_mood_7 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	12 	level_mood_6 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	13 	level_mood_5 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	14 	level_mood_4 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	15 	level_mood_3 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	16 	level_mood_2 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	17 	level_mood_1 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	18 	level_mood0 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	19 	level_mood1 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	20 	level_mood2 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	21 	level_mood3 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	22 	level_mood4 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	23 	level_mood5 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	24 	level_mood6 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	25 	level_mood7 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	26 	level_mood8 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	27 	level_mood9 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	28 	level_mood10 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	29 	level_mood_10_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	30 	level_mood_9_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	31 	level_mood_8_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	32 	level_mood_7_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	33 	level_mood_6_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	34 	level_mood_5_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	35 	level_mood_4_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	36 	level_mood_3_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	37 	level_mood_2_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	38 	level_mood_1_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	39 	level_mood0_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	40 	level_mood1_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	41 	level_mood2_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	42 	level_mood3_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	43 	level_mood4_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	44 	level_mood5_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	45 	level_mood6_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	46 	level_mood7_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	47 	level_mood8_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	48 	level_mood9_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	49 	level_mood10_to 	double(6,2) 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	50 	remember_token 	varchar(100) 	utf8mb4_unicode_ci 		Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	51 	created_at 	timestamp 			Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	52 	updated_at 	timestamp 

i jeszcze tabela hash.

 	1 	idPodstawowy 	bigint(20) 		UNSIGNED 	Nie 	Brak 		AUTO_INCREMENT 	Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	2 	id_usersIndeks 	bigint(20) 		UNSIGNED 	Nie 	Brak 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	3 	if_true 	tinyint(4) 			Nie 	Brak 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	4 	hash 	char(10) 	utf8mb4_unicode_ci 		Tak 	NULL 			Zmień Zmień 	Usuń Usuń 	

    Podstawowy Podstawowy
    Jednoznaczny Jednoznaczny
    Indeks Indeks
    Przestrzenny Przestrzenny
    Więcej

	5 	remember_token 	varchar(100) 	utf8mb4_unicode_ci

i w tej tabeli hash jeżeli jest if_true na 1 to zanczy że za pomocą hasha (hash) można się zalogować i przeglądać.

Ja nie wiem jak to zrobić za pomocą ról.

2

Przeczytałeś co napisałeś?

natomiast mam teraz takie coś, że mam akcje dla >użytkoniwków i mam akcje dla innych użytkowników >którzy nie są użytkiwnikami,

Zastanów się sam dokładnie co chcesz osiągnąć i zadaj pytanie tak, żeby dało radę to zrozumieć.

0

No chodzi o to, że jest sobie zwykły użytkownik o loginie tomi i dla tego użytkownika są role i wiem jak te role zapisać natomiast jak zrobić role dla np lekarza, który by tylko przeglądał zawartośc dla użytkownika tomi ale nic nie dodawał ani modyfikował tylko wpisał nazwę użytkownika i hash, który nadaje użytkownik tomi.

1

No ale to masz odrębną rolę:
-lekarz: uprawnienia tylko do odczytu.
Dajesz nową rolę, ustawiasz sobie np. bramę na odpowiednie akcje.
https://laravel.com/docs/7.x/authorization#writing-gates

0

Ja mam coś takiego w routingu

Route::group(
    ['middleware' => ['auth']],
    function () {
    Route::get('/home', 'Main\MainController@index')->name('home');

    
        
    }
    );

I teraz hash jest w innej tabeli i jeszcze jest pole if_true jeśli to jest na 1 to dalej sprawdzać czy hash jest poprawny jak to zrobić za pomocą role czyli tych ustawień w pliku routes.php bo tak robiłem role.

0

Ja to zrobię chyba w taki sposób.

use App\Hashe;

public function loginDr(Request $request) {
        $Hashe = array(
             "login" => $request->get("id"),
            "hash" => $request->get("password")
            
        );
        if ($request->get('login') == "" or $request->get('password') == "" ) {
            return Redirect('/User/Login')->with('error','Uzupełnij pole login i hasło');
        }
        if (Auth::attempt($Hashe) ) {
            return Redirect("/Main");
        }
        else {
            return Redirect('/User/Login')->with('error','Nie prawidłowy login lub hasło');
        }
    }

Tylko teraz ten hash nie jest hasohowany w bazie jak zrobić żeby funkcja Auth::attempt($Hashe) nie sprawdzała pola w bazie za pmoca hasha

I teraz tutaj "login" => $request->get("id"), jak zrobić, żeby przed id_users w bazie dostać się do tabeli user i wyciągnąć jego login czy tutaj można jakoś dać zapytanie za pomoca join ?

1 użytkowników online, w tym zalogowanych: 0, gości: 1