1
Q

Where are controllers stored? (by default)

A

app/Http/Controllers

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

Create a controller using Artisan!

A

php artisan make:controller NAME

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

Given a controller named “UserController” and the route “/user/{id}”, create a Route::get that uses the show method of said controller!

A

Route::get('/user/{id}', [UserController::class, 'show']);

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

What should the method name be if you have a controller dedicated to a singular action?

A

(in class of said controller)
public function \_\_invoke() { // ... }

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

Given the route “/server” and the single function controller “ProvisionServer”, make a Route::post that invokes the function!

A

Route::post('/server', ProvisionServer::class);

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

Assign the middleware “auth” to this route:
Route::get(‘/profile’, [UserController::class, ‘show’]);

A

Route::get('/profile', [UserController::class, 'show'])->middleware('auth');

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

Which interface should you implement to specify middleware within your controller class?

A

HasMiddleware

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

Create a controller using Artisan, that assigns the “create”, “read”, “update” and “delete” routes to said controller!

A

php artisan make:controller ExampleController --resource

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

Register a resource’s CRUD (create, read, update and delete) methods in a route!

A

Route::resource('example', ExampleController::class);

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

Which method should you call while defining a resource route to not let the page go to the default 404 page when a resource model is not found?

A

missing();

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

Include soft deleted models in this resource route:
Route::resource(‘photos’, PhotoController::class);

A

Route::resource('example', ExampleController::class)->withTrashed();

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

Make a controller using Artisan, that type-hints a model instance!

A

php artisan make:controller ExampleController --model=ExampleModel --resource

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

Which option do you need to add to your Artisan command for the generation of a form request class for a controllers storage and update methods!

A

--requests

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

How can you limit the actions of a resource route to a specific subset of actions?

A
INSERT ROUTE->only([
    'action one', 'action two', ...
]);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can you exclude specific actions of a resource route?

A
INSERT ROUTE->except([
    'action one', ...
]);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Declare a resource route that will be consumed by APIs!

A

Route::apiResource('example', ExampleController::class);

17
Q

Register multiple API resource controllers at once!

A
Route::apiResources([
    'example1' => Example1Controller::class,
    'example2' => Example2Controller::class,
]);
18
Q

Generate an API resource controller using Artisan!

A

php artisan make:controller ExampleController –api

19
Q

What do you need to do to define a route to a nested resource?

What will the URIs look like?

A
Route::resource('examples.beispiele', ExampleController::class);

/examples/{example}/beispiele/{beispiel}
20
Q

Which method enables automatic scoping for a nested model binding?

21
Q

What is shallow nesting?

A

Often, it is not entirely necessary to have both the parent and the child IDs within a URI since the child ID is already a unique identifier. When using unique identifiers such as auto-incrementing primary keys to identify your models in URI segments, you may choose to use “shallow nesting”

22
Q

Which method do you need to use to use shallow nesting?

A

INSERT ROUTE->shallow();

23
Q

How can you name the actions of controllers?

A
INSERT ROUTE->names([
    'example' => 'examples.beispiele'
]);
24
Q

Create a scoped nested resource!

What will the URIs look like?

A
Route:.resource('examples.beispiele', ExampleController::class)->scoped([
    'beispiel' => 'spezifischesbeispiel',
]);

/examples/{example}/beispiele/{beispiel:spezifischesbeispiel}
25
Q

Which language will Route::resource create resource URIs in by default?

26
Q

How can you localize the action verbs of a Route::resource?
Localize the actions “create” and “edit” into German!

A

(at the beginning of the boot method within App\Providers\AppServiceProvider)

Route::resourceVerbs([
    'create' => 'erstellen',
    'edit' => 'bearbeiten',
]);
27
Q

What are resources, that only have a singular instance, called?

A

Singleton resources

28
Q

Register a singleton resource controller route!

A

Route::singleton('example', ExampleController::class);

29
Q

Which method should you use so that you can turn a singleton resource route into something, that also has a DELETE route?

A

Route::singleton(...)->creatable();

30
Q

Which 3 action routes are not registered for singleton resources, that do exist for singleton…->creatable resources?

A

create, store and destroy

31
Q

What should you use instead of “creatable()” if you don’t want create and store action routes to be defined, but do want the registration of the destroy route?

A

Route::singleton(...)->destroyable();

32
Q

Create a singleton resource for an API!

A

Route::apiSingleton('example', ExampleController::class);

33
Q

How can you register the store and destroy routes for an API singleton resource?

A

Route::apiSingleton(...)->creatable();