Laravel docs Flashcards

1
Q

what does a basic route accept in laravel?

A

URI and a closure

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

what is URI?

A

A Uniform Resource Identifier (URI) is a string of characters that uniquely identify a name or a resource on the internet. A URI identifies a resource by name, location, or both. URIs have two specializations known as Uniform Resource Locator (URL), and Uniform Resource Name (URN).

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

what is URL?

A

A Uniform Resource Locator (URL) is a type of URI that specifies not only a resource, but how to reach it on the internet—like http://, ftp://, or mailto://.

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

what is URN?

A

A Uniform Resource Name (URN) is a type of URI that uses the specific naming scheme of urn:—like urn:isbn:0-486-27557-4 or urn:isbn:0-395-36341-1.

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

what is a closure?

A

it’s an anonymous function (a function that has no name)

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

what provider loads routes?

A

App\Providers\RouteServiceProvider

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

what file do we write web routes?

A

routes/web.php

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

what middle ware is assigned to the routes in web.php?

A

web middleware group

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

what features does a web middleware provide?

A

state session and CSRF token protection

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

what file do we write api routes?

A

routes/api.php

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

what is the state of api routes?

A

stateless

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

what is the middleware group assigned to api routes?

A

api middleware

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

What’s A Stateful API?

A

A stateful API relies on the server to maintain the state of the client’s session. In other words, a stateful API requires the server to keep track of the current state of the client’s session, which includes all the information necessary to identify the client and its current form. This allows the server to provide a more seamless user experience since the client doesn’t have to resend the same information with every other request.

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

What’s A Stateless API?

A

A stateless API is an API that does not rely on the server to maintain the state of the client’s session. In a stateless API, every request the client makes contains all the necessary information to identify the client and the session’s current state. The server processes each request independently and stores no information about the client’s session.

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

Pros of Stateful API?

A

1 - Better Performance: Stateful APIs allow developers to store data, such as user session information, persistently and make it available for the duration of the user’s session. This makes it easier for developers to create more responsive and reliable applications. Stateful APIs also give developers more control over their applications by allowing them to manage their own state. This enables them to optimise their code for better performance and scalability without relying on third-party services or libraries.
2 - Real-Time Updates: Developers can create applications that respond quickly to changes and user input using stateful APIs. This makes them an excellent choice for applications that need to be highly responsive, such as online gaming or video streaming services. Also, stateful APIs allow developers to store data and manage the state between requests, making it easier to keep track of user interactions and respond accordingly. This makes them ideal for creating real-time applications that require quick responses from the server side.
3 - Seamless User Experience: Stateful APIs allow developers to store and efficiently manage data, which is essential for creating applications that provide a smooth and consistent user experience. Stateful APIs also enable developers to store data in an orderly manner, which helps them develop applications that can respond quickly to user requests. This makes it easier for developers to create rapidly scalable applications and provide users with a better overall experience.

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

Cons of Stateful API?

A

1 - Complexity: Implementing and maintaining a stateful API can be more complex than a stateless API, as the server needs to keep track of the state of every client’s session. This can require additional resources and be prone to errors if incorrectly implemented.
2 - Less Scalable: Stateful APIs are less scalable than stateless APIs because they store state information in memory or a database. This means each request to the API requires additional resources, such as a database query, which can slow down the process of responding to requests if the number of requests can cause bottlenecks and other performance issues.
3 - Higher Network Usage: Stateful APIs can use more bandwidth than stateless APIs since the server needs to send and receive more data to maintain the state of the client’s session. In other words, stateful APIs require more data to be transferred between the client and server, which increases network usage.

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

Pros of Stateless API?

A

1 - Simplicity: Stateless APIs are becoming increasingly popular due to their simplicity and scalability. They are easy to implement and maintain, making them the perfect choice for businesses looking to quickly develop and deploy applications. Stateless APIs also provide developers with a way to quickly create, store, and access data without worrying about the state of the application or server. This makes them more reliable and efficient than traditional APIs. Additionally, they are much easier to scale up or down depending on the needs of the business.
2 - Cacheable: Stateless APIs are cacheable, meaning that they can be stored in a local cache or on a remote server for faster access. This allows developers to reduce latency and improve user experience by providing faster responses when data is requested from the API. By caching the stateless API, developers can ensure that requests are served quickly and efficiently, making their applications more responsive and reliable.
3 - Compatibility: Another advantage of using stateless APIs is that they are more compatible with different systems and applications. They also require less maintenance since there is no need to keep track of user information or data. This makes them ideal for companies who want to develop applications quickly without having to worry about managing user data or information.

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

Cons of Stateless API?

A

1 - Performance: Stateless APIs can be slower and less efficient than stateful APIs, especially for applications that require many small requests since each request contains all the necessary information, including authentication, headers, and parameters.
2 - Real-Time Updates: Stateless APIs may not be suitable for applications that require real-time updates or high levels of interactivity since the server can only push new data to the client without the client having to request it.
3 - No Session Management: Stateless APIs do not maintain the state of the client’s session, making it difficult to manage user sessions, perform user tracking or enforce security measures, such as rate limiting and access control.

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

how can we modify routes prefixes?

A

in RouteServiceProvider Class

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

What are the available router methods?

A

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);

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

how can we register more than one HTTP method to the same URI?

A

Route::match([‘get’, ‘post’], ‘/’, function () {
// …
});

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

how can we register all HTTP methods to the same URI?

A

Route::any(‘/’, function () {
// …
});

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

what is the difference between HTTP methods?

A

GET : retrieve something
POST: create something
PUT: update something (required entire body to be changed)
PATCH : update something (required only the part we want to change)
DELETE : Delete something

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

how do we redirect a route?

A

Route::redirect(‘/here’, ‘/there’);

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

what is dependency injection?

A

it’s a technique where an object or a method supply’s another object with it’s dependency

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

what are the types of dependency injection?

A

1 - constructor injection : the dependencies are provided in the constructor
2 - setter injection : the client exposes a setter method in which the injector uses to inject the dependency
3 - interface injection: the dependency provides an injector method that will inject the dependency into any client passed to it . client must implement an interface that exposes a setter method that accepts the dependency

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

what is the adjacent principle to Dependency injection?

A

Dependency inversion principle

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

what is Dependency inversion principle?

A

Entities must depend on abstractions, not on concretions. It states that the high-level module must not depend on the low-level module, but they should depend on abstractions.

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

what is used in laravel for dependency injection?

A

Service Container

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

should we use concrete class in dependency injection?

A

No we should use an interface

31
Q

how does laravel provide automatic dependency injection?

A

using type hinting

32
Q

what does laravel use to automatically resolve dependencies?

A

it uses PHP reflection

33
Q

what is php reflection used for?

A

it’s a way to find information about classes at runtime

34
Q

is dependency injection resolved at runtime or compile time?

A

at runtime

35
Q

Why do we use the facade pattern?

A

when we have a complex system that has alot of small objects that each have a small task to do it makes sense that if we want a client to interact with all of these objects that we create a facade that interacts with these objects instead of the client

36
Q

what is the facade pattern?

A

the facade pattern provides a unified interface to a set of interfaces in a sub system , facade defines a higher level interface that makes the sub system easier to use.

37
Q

how does laravel uses facade?

A

the facade provides access to an object from the service container by extending the ‘facade’ class and using the getFacadeAccessor() function we return the name of the object we want to retrieve and then laravel usses the __callStatic() Method on the retrieved object

38
Q

what is real time facade in laravel?

A

it allows us to treat any class as a facade we can just add ‘facade’ before class name in use statement and that allows us not to use dependency injection

39
Q

how to make a migration in laravel?

A

php artisan make:migration create_posts_table

40
Q

how does laravel know the order of the migration?

A

by adding a timestamp to each migration

41
Q

what to do when your migration files get too big?

A

you can squash them

42
Q

how to squash database migrations?

A

php artisan schema:dumb

43
Q

what does squashing database migrations do?

A

create a single ‘schema’ file or SQL file

44
Q

what methods does each migration has?

A

up and down

45
Q

what does the ‘up’ method do in a migration?

A

it’s responsible for adding table , columns or indexes

46
Q

what does the down method do in a migration?

A

it’s used to reverse the up method

47
Q

how to run the migration?

A

php artisan migrate

48
Q

how to check which migration was ran?

A

php artisan migrate:status

49
Q

how to roll the last batch of migrations?

A

php artisan migrate:rollback

50
Q

how to roll back all of the migrations?

A

php artisan migrate:reset

51
Q

how to create a model using php artisan?

A

php artisan make:model

52
Q

how to show a model relations in php artisan

A

php artisan model:show ModelName

53
Q

how to specify the model table name?

A

using $table property

54
Q

how does eloquent determine the default table name for a model?

A

using snake case convention meaning that Flight Model maps to flights table

55
Q

does laravel support composite keys?

A

No

56
Q

how to retrieve all the records from eloquent model?

A

using all();

57
Q

what is the entry point for any request?

A

public/index.php

58
Q

what happens after the request arrives at index.php?

A

1 - composer autoloader
2 - bootstrap/app.php

59
Q

what is the first action taken by laravel itself in the request cycle?

A

loading the service container

60
Q

what happens after service container is loaded by laravel?

A

the request goes to HTTP Kernel or Console Kernel

61
Q

what is the kernel in laravel?

A

it’s the central location that all requests go through

62
Q

where is the HTTP kernel located?

A

app/HTTP/kernel.php

63
Q

what is run before the request is executed

A

an array of bootstrappers inside the kernel class

64
Q

what do the bootstrappers do in the kernel?

A

they configure:

1 - error handling
2 - logging
3 - detect application environment
4 - middlewares
5 - service providers

65
Q

what is the responsibility of service providers?

A

they are responsible for bootstrapping all of laravel’s framework component and they are the most important thing

66
Q

where are service providers located?

A

config/app.php in providers array

67
Q

how does laravel handle service providers?

A

1 - call register
2 - call boot

68
Q

what happens to the request after service providers are bootstrapped?

A

it goes through the routes file

69
Q

what handles the response of the request?

A

the kernel ‘handle’ method which then sends the response back to index.php ‘send’ method

70
Q

when will you manually register a class inside a service container?

A

1 - custom class that implements an interface nd we want to type hint it in the constructor
2 - writing a package

71
Q

where do we bind interfaces to service containers?

A

in service providers

72
Q

do we need to manually bind concrete classes to service containers?

A

No, only interfaces as the service container can use reflection to type hint the concrete classes

73
Q

what is the difference between singleton bind and scoped singleton bind?

A

singleton -> binds only one time and is available globally as the same object
scoped singleton -> binds only one time through a request lifecycle

74
Q

what is the definition of the singleton pattern?

A

the singleton pattern ensures there is only one instance and provides a global access to it