Trouble creating my first Laravel controller - php

I just started using and watched a youtube video how to start.
I try to make my first controller, so I execute this command:
php artisan controller:make WelcomeController
I get an exception:
[InvalidArgumentException]
There are no commands defined in the "controller" namespace.
I am executing this in the root folder of the Laravel project.

The command is actually:
php artisan make:controller WelcomeController
You wrote controller:make instead of make:controller.
In the future you can run just php artisan and it will list all commands with a short description for each one, that way you can make sure you're running the correct command. If you want more details about a command, like usage and what options it accepts, you can run php artisan help [command]. So for your command it would be:
php artisan help make:controller

Related

Where do I run "php artisan make:migration posts" on WIndows?

I am following this tutorial: http://www.findalltogether.com/tutorial/simple-blog-application-in-laravel-5-part-1-setup-database/ to set up a Blog using Laravel.
In the tutorial, it says to make migrations I've to run php artisan make:migration posts. Where do I run this? I tried bash but received the error: Could not open input file: artisan.
I'm on Windows, using xampp - could this be a reason?
Thank you
You have to go in folder where artisan is located (usally root of project) and with CMD or CONSOLE write php artisan make:migration posts
First Navigate to your project directory from command prompt if you have installed the laravel in your project so there should be artisan available you may find by typing "dir" once you find artisan there you should run your respective command. Moreover once you reached to your project directory for testing purpose you may write this line
" php artisan " (without quotes) and press enter you will see all the list of commands available in artisan.
Thanks

How to properly remove a table from folder migration in laravel? (With artisan command)

when you use comand by example:
php artisan make:migration create_tasks_table --create=tasks
it creates a table file and dependency link inside of file
\vendor\composer\autoload_classmap.php
How I can do something like?
php artisan remove:table:file create_Task_table
No such command exists in artisan console. However, you can either make one such command or just delete the migration and execute the following command in the console.
composer dump-autoload

Running Artisan Command from laravel 4.2 Controller

I am trying to execute some custom artisan command from controller like
Artisan::call('php artisan MyCustomCommand');
but it works fine when I execute
php artisan MuCustomCommand from CLI.
I have registered command in app/start/artisan.php.
Even Artisan::call('php artisan --help'); is not working.
You should run artisan command like this from your controller .
Example :
Artisan::call('migrate:install');
So Instead of doing Artisan::call('php artisan MyCustomCommand');
You should do
Artisan::call('MyCustomCommand');
Here is the documentation
Hope it helps :)

"There are no commands defined in the 'command' namespace." after running command:make in Laravel

Just like in title. I'm trying to run from artisan
php artisan command:make NameOfCommand
but all I see is
There are no commands defined in the "command" namespace.
Any idea what is this?
As the documentation says (Current version is 5.2 at this moment):
Once your command is finished, you need to register it with Artisan so
it will be available for use. This is done within the
app/Console/Kernel.php file.
in the Kernel.php file you must add:
protected $commands = [
Commands\NameOfCommand::class
];
(ref: https://laravel.com/docs/5.2/artisan#registering-commands)
You have misplaced the command it is
php artisan make:command NameOfCommand
and not
php artisan command:make NameOfCommand
If you have simply write php artisan within your command prompt it'll show you the list of commands over there have a look
In laravel 5.2 use php artisan make:console NameOfCommand

How do I create a laravel artisan command?

I want to create the commands order:process and order:lock. So far, I have figured out that I need to run php artisan command:make process --namespace=order to create the order:process class file. Then I need to set the $name value in the app/commands/process.php to 'order:process'. This is where I'm stuck.
I think I need to add something to app/start/artisan.php to make the command usable, but I can't figure out what. I've tried Artisan::add(new order\process); and Artisan::add(new process);, but neither of these work. What do I need to do, to get my new commands available to be run from the command line? I know the problem is to do with the use of a namespace, but I can't find any documentation on artisan commands that use namespaces.
For laravel 5.0
php artisan make:console Foo --command=foo:do
Edit your commands located in app/Console/Commands/Foo.php
Then register your commands by adding an entry to app/Console/Kernel.php
protected $commands = [
'Cloudlite\Console\Commands\Inspire',
'Cloudlite\Console\Commands\EmailParser',
'Cloudlite\Console\Commands\Foo',
];
You can now run like the following (example default option, edit Foo.php)
php artisan foo:do example=1
First create them with artisan command
php artisan command:make OrderProcessCommand --command=order:process
php artisan command:make OrderLockCommand --command=order:lock
Edit your commands located in app/commands
Then register your commands in app/start/artisan.php
Artisan::add(new OrderProcessCommand);
Artisan::add(new OrderLockCommand);
I still have no idea how to use namespaces, but I have figured this part out.
The answer is, to use php artisan command:make orderProcessCommand, and register that with Artisan::add(new orderProcessCommand);. The in orderProcessCommand.php, set the $name to order:process. Artisan will read the class as directed by the registration command, but make it available to be called as described in the $name field.

Categories