Laravel Artisan Generator Command: The make:request Command

December 7, 2016 —John Koster

The make:request command can be used to generate new request validation request classes. The command accepts a name for the newly created request class. The name will be used as the name of the class and the file.

The following example demonstrates how to call the make:request command:

1# Generate a new form request validation request class.
2php artisan make:request StoreDrinksPostRequest

A new app/Http/Requests/StoreDrinksPostRequest.php file would be created and contain contents similar to the following:

1<?php
2 
3namespace App\Http\Requests;
4 
5use App\Http\Requests\Request;
6 
7class StoreDrinksPostRequest extends Request
8{
9 /**
10 * Determine if the user is authorized to make this request.
11 *
12 * @return bool
13 */
14 public function authorize()
15 {
16 return false;
17 }
18 
19 /**
20 * Get the validation rules that apply to the request.
21 *
22 * @return array
23 */
24 public function rules()
25 {
26 return [
27 //
28 ];
29 }
30}

This command will not overwrite any existing form request validation request classes that have the same name. An error stating Request already exists! will be displayed instead.

The make:request command is also capable of generated namespaced classes. Accomplish this by separating namespace sections using the \ when supplying the request name. A nested directory will be created and the correct namespace will be set on the generated class.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.