How to create a command for a Laravel 4 package? - php

The docs says that we can create a command for a package in Laravel 4.1 typing:
php artisan command:make AssignUsers --bench="vendor/package"
But it seems to not be working, I got the following error message:
[RuntimeException]
The "--bench" option does not exist.
Is there a way to create a command for a Laravel 4 package?

I used the standard artisan command to create a command into my package:
php artisan command:make CreateUsers \
--path="workbench/vendor/package/src/vendor/package"
After that, to make it available in the consumer application I had to add the following into my package's ServiceProvider (in the boot method):
$this->app->bind('vendor::command.user.create', function($app) {
return new UserCreateCommand();
});
$this->commands(array(
'vendor::command.user.create'
));
After that, everything will work fine.

when you run you will sse the list of arguments for make
php artisan command:make --help
you should see something like
Usage:
command:make [--command[="..."]] [--path[="..."]] [--namespace[="..."]] name
Arguments:
name The name of the command.
Options:
--command The terminal command that should be assigned.
--path The path where the command should be stored.
--namespace The command namespace.
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction (-n) Do not ask any interactive question.
--env The environment the command should run under.
as you can see from that output there is no argument bench
the proper way to do it is
php artisan command:make AssignUsers
then go to /app/start/artisan.php and add the following line
Artisan::add(new AssignUsers);
then edit the generated file in /app/commands/AssignUsers.php
change the value of $name to AssignUsers
and you are done.

Related

How can I debug php bin/console make:migration command freezing?

I am developing a web app using Symfony. I have successfully been using console commands fine with my project. I must have done something because now the command php bin/console make:migration freezes, with no output even in verbose mode. The command php bin/console make:entity works fine and makes me think there is something wrong with the database connection. Steps I have tried:
Make sure the DB version is present in .env file.
Restarted server
Deleted cache
Deleted entire project and cloned from git and ran composer install
The app still works as intended, but I cannot make a migration. The command simply hangs with no errors. Any suggestions on how to debug this?
You can add different levels of verbosity using the parameter "-v", as the Console list explains:
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Launch php bin/console make:migration -vvv to debug and see why it hangs.
It is not frozen. In this update, they have forgot to print the message.
The message is "Are you sure you wish to continue? y/i"
If you enter y and hit enter it will be continued.

Not enough arguments (missing: "key"). in laravel php artisan cache:forget

When i try to remove my all cache file from laravel 5.5 project i got some error during run this command
php artisan cache:forget
Not enough arguments (missing: "key").
use command php artisan cache:forget -h for see list Arguments and options.
this is list agruments and option of cache:forget command larvel 5.4
Arguments:
key The key to remove
store The store to remove the key from
Options:
-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 output and 3 for debug
if you want remove all cache file you can run this command
php artisan cache:clear
php artisan config:cache
and see more artisan command
php artisan list
You can use
php artisan cache:clear
after key generate with this command:
php artisan key:generate
For removing a entire Cache you can use Cache::flush();
For removing a key from Cache u can use Cache::forget('key') programmatically.
You can also use artisan console
php artisan cache:forget key="yourkey"
Hope this helps

Stuck at installing laravel/passport programmatically

To create a personal access client with passport in laravel, I need to run this command: php artisan passport:client --personal
I'm trying to run this command through Artisan::call('command', ['--flag'=>'value'])
The issue I'm having here is, passport prompts for an input to name the access token or accept a default one and the command gets stuck there. Is there any way I can give it any input? The Enter key press does the work on console.
Solution
Default Name: php artisan passport:client --personal --no-interaction
Custom Name: php artisan passport:client --personal --name=AccessTokenName
Found it in the source: https://github.com/laravel/passport/blob/2.0/src/Console/ClientCommand.php
Try running the command with the --no-interaction flag set. See php artisan passport:client --help for more options.

How do I remove old artisan command from Kernel in Laravel 5

I have created some Command files into my Laravel Application. Laravel version is 5.2. I set command like: get:email in the Command file. Also call the Command file into Kernel.php. After that I can see the artisan command list by typing the command php artisan list. as like as below:
//output
get:email
And I changed the command title get:email to get-bq:email. When I run the command php artisan get-bq:email -- its working nicely. Also I can see the list by typing the command php artisan list::
//output
get-bq:email
Issue / Problem: Both commands are working. But I won't to work with both of them. I have done the following things:
modified command file as well as command
run composer dump-autoload -o
run composer update
remove vendor and storage folder then run composer update again.
Still the old command is working into my system.
What I want: How May I remove my old commands from my Laravel(5.2) application?
Run these commands:
php artisan cache:clear
php artisan config:clear
These commands will clear app cache and config cache and recreate it.
I've had the same problem recently.
Repoeatedly tried
php artisan cache:clear
php artisan config:clear
and the cached Kernal command wouldn't clear.
In desperation i killed the queue worker terminal and restarted the queue with the command
php artisan queue:work
The issue stopped.

Laravel/Lumen - missing commands in Artisan console

I have a problem with runing Laravel's Artisan. There are most of the commands missing. Everything worked fine till the last composer/code update.
For an example if I write php artisan migrate, I get following error: Command "migrate" is not defined.
Below is an example of output that I get by typing php artisan.
Laravel Framework version Lumen (5.1.6) (Laravel Components 5.1.*)
Usage:
command [options] [arguments]
Options:
-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 output and 3 for debug
Available commands:
help Displays help for a command
list Lists commands
serve Serve the application on the PHP development server
schedule
schedule:run Run the scheduled commands
Does anyone have any ideas how to fix this?
It seems there was a problem with composer. Somehow composer.lock got into git ignore list and libraries used on production were different than the ones used in development.
The syntax has changed to php artisan make:migration.
You can see a full list of commands by running php artisan list

Categories