Laravel Flashcards

1
Q

What are middlewares in Laravel?

A

Middleware in Laravel is the program that executes before a controller responds to a request. It is a method of preventing requests from reaching the controller and processing them instead. Logging, caching, authentication, and permission are just a few applications for this.

php artisan make:middleware Authenticate

Global middleware
Route middleware
Controller middleware
Terminable middleware

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Laravel Passport?

A

Is an OAuth server implementation, and is used to offer OAuth authorization for your application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Laravel Sanctum?

A

Sanctum is an authentication library for “simpler” token-based authentication for clients that need it (i.e. mobile apps) but also offers cookie-based authentication for SPAs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a Laravel guard?

A

Guards in Laravel define how users are authenticated in your application. They determine where the application should look for user credentials and how to verify them. Laravel provides multiple guard drivers out of the box, such as “web” (for browser sessions) and “api” (for API token authentication).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a Laravel Gate?

A

Gates are used for defining and checking authorization policies in Laravel. They allow you to define fine-grained access control rules for different actions or operations in your application. Gates are often used within your code to check if a user is authorized to perform a specific action.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a Laravel Policy?

A

Policies are similar to gates but provide a more organized way to manage authorization logic for specific models in your application. Each model can have its own policy class that defines the authorization rules for that model’s actions (e.g., creating, updating, deleting).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the key differences between guards, gates and policies?

A

Guards: Guards handle user authentication and define where the application should look for user credentials (e.g., sessions, tokens).

Gates: Gates are used to define and check authorization policies for specific actions or operations in your application.

Policies: Policies are used to define authorization policies for specific models, making it easier to manage rules for CRUD operations related to those models.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Request Lifecycle

A

1 - index.php -> autoloading and creating the Laravel app instance

2 - Kernel -> Manage Req and Res objects. Also Middlewares

3 - Service Providers -> Dependency Injection

4 - Routing -> match route and send to controller

5 - Controller -> handle request and process data

6 - Model -> if controller needs

7 - Response -> after processing the request, the controller prepares a response.

8 - Middleware Again ->

9 - Send response

How well did you know this?
1
Not at all
2
3
4
5
Perfectly