Reputation: 131
I'm struggling to create more than one models (I don't want to run command every time to create a lot of models) using artisan command in Laravel 8 but it's giving me error.
What I tried is
php artisan make:model Photo Staff Product
The error I faced,
Too many arguments to "make:model" command, expected arguments "name".
Upvotes: 0
Views: 6168
Reputation: 29
you can prepare your artisan commands in a separate text file like a photo attached with this post select all and copy them then past all in the ide terminal and they will run all
Upvotes: -1
Reputation: 131
We can do this using OS-native shell. We have to write the PowerShell script to perform this tasks.
Here it is,
#checking if there is any artisan script present, if not then exit
if (!(Test-Path ".\artisan" -PathType Leaf)) {
echo "ERROR: Artisan not found in this directory"
exit
}
#promting user
$input = Read-Host -Prompt "Enter model names separated by commas"
if (!$input) {
echo "ERROR: No model names entered"
exit
}
else
{
$input = $input -replace '\s','' #removing white spaces if any
$input = $input -replace ',+',',' #removing more than 1 commas with single comma
#checking if input contains any special character using regex
if ( $input -match '[!@#\$%\^&\*\(\)\.\{\}\[\]\?\|\+\=\-\/]' ){
echo "ERROR: Incorrect model names";
exit
}
}
echo "Enter switches to create additional classes (like -msfc)"
$switch = Read-Host -Prompt "Enter the desired switches"
if (!$switch) {
echo "WARNING: No switch selected"
} else {
if ($switch -notmatch "-") {
$switch = "-" + $switch
}
if ($switch -notmatch "[mscf]") {
echo "ERROR: The switch can contain only [mscf] characters"
exit
}
}
$switch = $switch -replace '\s',''
#spliting the string
$models = $input.Split(",")
foreach ($model in $models) {
echo "Creating model $model"
php artisan make:model $model $switch
}
save the file using the .ps1
extension starting with name artisan (e.g. artisan-models.ps1
) and run directly using .\artisan-models.ps1
command.
Here's Link
Upvotes: 0
Reputation: 1636
As the error message suggests, it only expects one parameter, which is the name of the one, single, model you are trying to create. You cannot create multiple models in one artisan command.
If your terminal allows it, the up key will return you back to the previous command typed in, speeding up the process of generating models.
Upvotes: 1