Skip to main content

make:model - Less-Known Possible Options

Lesson 01/38 1:31
Autoplay

Lesson Overview

- Understanding all available options for make:model command
- Using interactive model creation prompts
- Generating related files (migrations, controllers, etc.)
- Creating resource controllers with automatic model binding

Of course, we all know about the Artisan command make:model. But do you know about all the available options and parameters? Let's examine those parameters and see what we can generate with the Model.


First, when creating a new Model, if you don't pass any parameters to the Artisan command, you will see a prompt to enter the Model name and choose what to create alongside the Model.

After selecting the wanted options, they are created.


Now, let's see the available options if you want to specify them manually as Artisan command flags.

You don't need to remember them. All available options can be checked by providing -h or --help to the artisan command.

I think creating a Migration and Controller together with the Model is the most common.

The resource Controller will be created if you provide the -r option.

In the Controller, we have seven methods, and to them, the Route Model Binding is injected automatically.

use App\Models\Task;
use Illuminate\Http\Request;
 
class TaskController extends Controller
{
public function index()
{
//
}
 
public function create()
{
//
}
 
public function store(Request $request)
{
//
}
 
public function show(Task $task)
{
//
}
 
public function edit(Task $task)
{
//
}
 
public function update(Request $request, Task $task)
{
//
}
 
public function destroy(Task $task)
{
//
}
}

The same is if you create the Form Request with the resource Controller.

All Form Requests are injected automatically.

use App\Http\Requests\StoreProjectRequest;
use App\Http\Requests\UpdateProjectRequest;
use App\Models\Project;
 
class ProjectController extends Controller
{
public function index()
{
//
}
 
public function create()
{
//
}
 
public function store(StoreProjectRequest $request)
{
//
}
 
public function show(Project $project)
{
//
}
 
public function edit(Project $project)
{
//
}
 
public function update(UpdateProjectRequest $request, Project $project)
{
//
}
 
public function destroy(Project $project)
{
//
}
}

Or if you need everything using the option -a or --all, everything will be generated.

So, you see how many things you can generate from one make:model artisan command.

Comments & Discussion

R
Rafat ✓ Link copied!

Do your courses contain videos?

M
Modestas ✓ Link copied!

We are trying to move away from video courses and focus on text courses. This is because they are easier to keep up-to date and react to any mistakes/improvements.

So in this case, no, there is no video for this specifically.

D
Daniel ✓ Link copied!

Yeah this is actually better. love the idea

V
Vito ✓ Link copied!

Just subscribed. This was my first lesson. The writing flows very nice!

LN
Loganathan Natarajan ✓ Link copied!

Thanks for the text tutorials.. It's easy to read.

�S
Đào Sơn ✓ Link copied!

very easy and simple , dont make video for course , thank

V
vance ✓ Link copied!

thanks for the text tutorials , they are easy to follow

BE
Bilal El Haj ✓ Link copied!

there's an error in the file:

--h isn't working. -h is right.

PK
Povilas Korop ✓ Link copied!

Thanks, good notice! Fixed right away.

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.