I create a command through make:command
php artisan make:command ResetDBCommand
Then I would like to run the two command in handler
php artisan ide:models
php artisan db:seed
However, it's not work for me to fire the two command automatically through the below codes
Artisan::call('db:seed');
$console->writeln('db:seed done.');
Artisan::call('ide:models--force');
$console->writeln('ide:models done.');
Error:
The command "ide:models--force" does not exist.
how can I do that?
The correct command is ide-helper:models you can confirm this if you do:
php artisan help ide:models
You get:
[...]
Usage:
ide-helper:models [options] [--] [<model>...]
which indicates that Laravel does automatically resolve this command when called in the command line. However such resolution mechanism does not exist when calling it programmatically.
Another issue is that --force is not a valid option in ide-helper:models here's what you can do though:
Artisan::call('db:seed');
$console->writeln('db:seed done.');
// Uncomment one of the two
// Artisan::call('ide-helper:models --nowrite'); // Only write metadata in the _ide_helper_models.php file
// Artisan::call('ide-helper:models --write'); // Write metadata on models
// ------
$console->writeln('ide:models done.');
Pick whichever one you prefer accordingly
Tested the above in Laravel 8
Related
I'm trying to add an icon_path column to an existing table called tbl_device
by using php artisan make:migration add_icon_path_to_tbl_device_table --table=tbl_device
and after running php artisan migrate, it gives me this error.
PHP Fatal error: Cannot declare class CreateFailedJobsTable, because the name is already in use in ...path\database\migrations\<date>_create_failed_jobs_table.php
Cannot declare class CreateFailedJobsTable, because the name is already in use
I've also tried manually adding the icon_path column to the create_tbl_device_table.php migration and after running php artisan migrate it says Nothing to migrate.
I think I followed all the instructions.. any idea where I went wrong?
Call artisan migrate command only for your specific migration using:
php artisan migrate --path=/database/migrations/my_migrations
And see if it works.
When I try to follow the instruction here (https://github.com/beyondcode/laravel-er-diagram-generator) I get the following error.
Symfony\Component\Debug\Exception\FatalThrowableError : Argument 1 passed to BeyondCode\ErdGenerator\GenerateDiagramCommand::getAllModelsFromEachDirectory() must be of the type array, null given, called in vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php on line 96
at vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php:101
97|
98| return $modelsFromDirectories;
99| }
100|
101| protected function getAllModelsFromEachDirectory(array $directories): Collection
102| {
103| return collect($directories)
104| ->map(function ($directory) {
105| return $this->modelFinder->getModelsInDirectory($directory)->all();
Exception trace:
1 BeyondCode\ErdGenerator\GenerateDiagramCommand::getAllModelsFromEachDirectory()
vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php:96
2 BeyondCode\ErdGenerator\GenerateDiagramCommand::getModelsThatShouldBeInspected()
vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php:57
Please use the argument -v to see more details.
I've already opened an issue in the repository.
Screen capture of the error:
Posting for others that may encounter same issue.
Confirm you are using the latest version 1.4.0 of the library
Also if you're using php artisan serve try to stop the server. Run php artisan config:cache, and restart the artisan sever.
Note that the reason why you might need to run php artisan config:cache is because Laravel does cache the app's configurations. if you changed or added new configurations you might explicitly need to clear the configuration cache so that Laravel can cache the new configurations.
If no solution yet. Try this
php artisan vendor:publish --provider=BeyondCode\\ErdGenerator\\ErdGeneratorServiceProvider.
Then repeat step 2.
As the title says; is there a way to delete/revert/rollback the creation of the files created when running php artisan make:model MyModel -mcr?
Something like:
php artisan destroy:model MyModel
.. and it "cascade" delete all related files?
Just do it manually, no command as of this writing
Delete the model first (if you don't) need the model any longer
Delete the migration from ...database/migrations folder
If you have already migrated i.e if you have already run php artisan migrate, log into your phpmyadmin or SQL(whichever the case is) and in your database, delete the table created by the migration
Still within your database, in the migrations folder, locate the row with that migration file name and delete the row.
Works for me, hope it helps!
When you run
php artisan make:model --help
command you must be see
Usage:
make:model [options] [--] <name>
Arguments:
name The name of the class
Options:
-a, --all Generate a migration, factory, and resource controller for the model
-c, --controller Create a new controller for the model
-f, --factory Create a new factory for the model
--force Create the class even if the model already exists
-m, --migration Create a new migration file for the model
-p, --pivot Indicates if the generated model should be a custom intermediate table model
-r, --resource Indicates if the generated controller should be a resource controller
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose outp
ut and 3 for debug
That mean dy default it is not poosible. You must be make your own artisan command for it. Also if you want know about artisan command options and arguments use
php artisan command_name --help
I have a custom artisan command with a signature:
protected $signature = 'user:update
{changedFrom : Timestamp to update users from - "yyyy-mm-dd hh:mm:ss"}
{--extras : Whether to update fringe case "extra" users}';
I am always forgetting the options and their format. I hoped I'd be able to view them in the CLI but the best I can do is to list the description of commands with php artisan.
Is there an artisan command to see the signature?
Adding --help to the command should output the available options.
php artisan user:update --help
I have been looking in the docs for a solution to make views with basic CURD operations but without much success.
I guess this might be pretty simple, but am missing something or not looking hard enough.
i can make models and controllers using the below artisan commands
php artisan make:model modelName
php artisan make:controller controllerName
But how do we make the basic CURD views. something like
php artisan make:views
cant find any doc for this. Please help
At the time of writing, there isn't a way to create views via artisan without writing your own command or using a third party package. You could write your own as already suggested or use sven/artisan-view.
if you are using laravel 5.1 or 5.2 this gist can help you make:view command just create command copy and paste the code from gist.
Step 1:
php artisan make:command MakeViewCommand
Step 2:
copy class from this gist
https://gist.github.com/umefarooq/ebc617dbf88260db1448
Laravel officially doesn't have any Artisan cammands for views.
But you could add third party plugins like Artisan View
Here's the link Artisan View
After adding this plugin to your project by the guide provided here you should be able to perform following cammands :
Create a view 'index.blade.php' in the default directory
$ php artisan make:view index
Create a view 'index.blade.php' in a subdirectory ('pages')
$ php artisan make:view pages.index
Create a view with a different file extension ('index.html')
$ php artisan make:view index --extension=html
There is very easy way to create a view(blade) file with php artisan make:view {view-name} command using Laravel More Command Package.
First Install Laravel More Command
composer require theanik/laravel-more-command --dev
Then Run
php artisan make:view {view-name}
For example
It create index.blade.php in resource/views directory
php artisan make:view index
It create index.blade.php in resource/views/user directory
php artisan make:view user/index
Thank you.
In v5.4 you need to create the command with:
php artisan make:command MakeView
and before you can use it, it must be registered in App/Console/Kernel like
protected $commands = [
Commands\MakeView::class
];
then you make a view like: php artisan make:view posts/create
To create a view (blade) file through command in laravel 8:
composer require theanik/laravel-more-command --dev
php artisan make:view abc.blade.php
You can install sven/artisan-view package to make view from CMD, to install package write this command:
composer require sven/artisan-view --dev
After installing it, you can make a single view or folder with all views that contain {index-create-update-show}
To make a single file we using this command:
php artisan make:view Name_of_view
For example
php artisan make:view index
To make a folder that contain all resources index - create - update - show write name of folder that contain all this files for example:
php artisan make:view Name_of_Folder -r
For example:
php artisan make:view blog -r
-r is a shorthand for --resource you can write full name or shorthand to make resource.
you can extend yields from master page if master page inside in directory layouts we write command sith this format
php artisan make:view index --extends=layouts.master --with-yields
layouts is a directory this directory may be with a different name in your project the idea is name_of_folder/master_page that you want to extend yields from it.
For more view docs