Architecture Flashcards
Every relevant information for the "Architecture" topic of the certification for laravel
What does a facade do?
They provide a “static” interface to classes that are available in the application’s service container.
What are helper functions?
Global functions, that make interacting with some Laravel features easier.
Describe “scope creep” in the context of facades!
Classes can easily grow too large, due to the ease of implementing more facades. The scope of responsibility should be split across multiple classes and not just fall onto one.
Which testing capabilities do facades offer, that normal static functions don’t?
You can inject a mock or stub and assert that various methods were called on the stub.
List the practical differences between facades and helper functions!
There are none.
Where is the facade base class located, which all facades extend?
Illuminate\Support\Facades\Facade
Describe real-time facades and what they let you do!
Using real-time facades, you may treat any class in your application as if it was a facade, which is very useful for testing / debugging purposes.
Given the class App\Contracts\Publisher, import a real-time facade of it!
use Facades\App\Contracts\Publisher;
Create a route for /hello, which displays “Hello World”!
Route::get('/hello', function () { return 'Hello World'; });
Where are routes defined by default? (In which file)
routes/web.php
What is Laravel Sanctum used for?
To turn your project into a stateless API.
Install Laravel Sanctum using artisan!
php artisan install:api
What is routing in Laravel?
It’s the process of defining URL patterns and associating them with certain actions or controllers in the application.
What are route parameters in Laravel?
Route parameters are dynamic values that are part of the URL pattern. They allow you to capture segments of the URI. For example, in Route::get('/user/{id}', function ($id) { return 'User '.$id; });
, {id} is a route parameter.
How do you define a route with a named parameter and set a default value in Laravel?
You can define a route with a named parameter and set a default value using the ? symbol and assigning a default value in the route definition. For example, Route::get('/user/{name?}', function ($name = 'Guest') { return 'User '.$name; });
sets a default value of ‘Guest’ if the name parameter is not provided.
What is a route middleware in Laravel?
Route middleware in Laravel is a way to filter and examine HTTP requests entering your application. Middleware can be assigned to individual routes or groups of routes, and can perform tasks like authentication, logging, or modifying the request or response.