You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Next you can clone the `.env.example` file into the `.env` file. This means that you have to create the same file in the `root` directory under a different name e.g. `.env` and copy paste the same credentials like `.env.example` file.
9
11
10
12
Laravel has a built-in CLI tool called `artisan`. Your application must generate a unique base 64 key that Laravel uses behind the scenes to bootstrap this project.
11
13
12
14
**Command:**
13
15
14
-
```sh
15
-
php artisan key:generate
16
-
```
16
+
```sh
17
+
php artisan key:generate
18
+
```
17
19
18
20
It will automatically find your `.env` file and place the base 64 value in the file.
As you can see it is necessary to create the `.env` file in your local to bootstrap the project. But `Laravel` contains 2 methods to connect to the database server.
@@ -33,89 +35,156 @@ As you can see it is necessary to create the `.env` file in your local to bootst
33
35
## Use of the `.env` variables:
34
36
35
37
When you create this file with copy paste credentials you can see default; the database variables are written something like this:
36
-
```
37
-
DB_CONNECTION=mysql
38
-
DB_HOST=127.0.0.1
39
-
DB_PORT=3306
40
-
DB_DATABASE=test_app
41
-
DB_USERNAME=root
42
-
DB_PASSWORD=
43
-
```
38
+
```
39
+
DB_CONNECTION=mysql
40
+
DB_HOST=127.0.0.1
41
+
DB_PORT=3306
42
+
DB_DATABASE=ui_multiauth
43
+
DB_USERNAME=root
44
+
DB_PASSWORD=
45
+
```
44
46
45
47
You can edit values according to your own database personal preference. I am using Postgres in this case.
46
48
47
-
## Use of the file located at the `config/database.php`
49
+
## Use of the file located at the `config/database.php`
48
50
49
51
**Note:** When Laravel bootstraps the project it gives priority to the `.env` file as compared to `config/**` files. You can see `config/database.php` file contains an associated array with default database settings like this.
It only uses one type of `people` and `1 table`. The website owner manually edits the database from the database server.
133
+
134
+
### Multi authentication
135
+
136
+
We store records in more than one table. So we authenticate them based on their credentials which will be stored in the database.
137
+
138
+
### Example:
139
+
**School management**:
140
+
We create authentication for different type of people for example: `Admins`, `Teachers`, `Moderators`, `Parents` & `Students`.
141
+
142
+
In this, we have to create multiple authentications for these types of people and each people represents a separate database table inside the database.
143
+
144
+
*What if we depend upon only a single table named `users` for all these people authentication?*
145
+
146
+
The table will be bloated and many records will reside on the same table and difficult to differentiate the user. So it is best practice to create separate table for each type of people.
147
+
148
+
The table will be bloated and many records will reside on the same table and difficult to differentiate the user. So it is best practice to create a separate table for each type of person.
149
+
150
+
- admins
151
+
- moderators
152
+
- students
153
+
- parents
154
+
- teachers
155
+
156
+
In a multi-authentication system, we can log in to different types of people at the same time. for example, `admin` and `student` can log in at the same time, and if you log out (destroy the session) from the admin account then it will not affect the `student` login session.
157
+
158
+
### Example 2:
159
+
160
+
At e-commerce website, we deal with 3 kinds of people.
161
+
`users`, `sellers` & `admins`.
162
+
163
+
### Role based Authentication
164
+
165
+
We usually see this kind of authentication on blogging websites. As there is only one owner of the website who creates different users and assigns them a role to manipulate the content of the website.
166
+
167
+
In this system we create 2 tables that has parent child relationship.
168
+
`roles` & `users` (In this table we create a column called `role_id` which is a foreign key and refers to the `roles` table column.)
169
+
170
+
In role-based authentication, the administrator has to create permissions to separate different permissions by role.
171
+
172
+
**Note:**
173
+
This repo is using a package named [laravel-ui](https://github.com/laravel/ui) and using a second authentication method and creating 2 tables `admins` & `users`.
174
+
175
+
The security of Laravel authentication depends on 2 things; `Guards`(Protectors) and `Providers`.
176
+
177
+
** Guard: **
178
+
The Guard explains how the user is authentic to each request. By default Laravel ships with `session` guard.
179
+
180
+
**What is session?**
181
+
182
+
*Whenever clients visit our website, our PHP server will generate a cookie with `session_ID` and some content inside the client browser and most importantly a `session` file will also be created in our server. It contains the same `session_ID` and content.
183
+
184
+
*Now when the user goes back to the website, the server will check and match Does the server's `session-ID` match the browser cookie? If so, the user is authentic.*
185
+
186
+
** Provider: **
187
+
What kind of permanent storage mechanism do you want to use to retrieve users? Do you want to use `eloquent` or `query builder`?
0 commit comments