I am new to laravel.
I have copied command to create controller from a book and I am trying to run that command:
php artisan Usercontroller:make users
I am getting error:
[InvalidArgumentException]
There are no commands defined in the "Usercontroller" namespace.
Did you mean this?
controller
Current working directory is project directory:
C:\wamp\www\laravel>
There is a typo in commmand,
you should use
php artisan controller:make users
Hope this helps.
Command should be
php artisan controller:make users
Related
Please note that "php artisan serve" works fine. Also it works with wrong spelling for "serve" as "serv". Previously, Laravel used to hint that "Did you mean php artisan serve" Im not understanding how artisan works now. Please provide some sources to read about this.
This is the screenshot for my question.
"php artisan serve" command is technical a simple Laravel command line command. You are able to create commands to. With the artisan command: php artisan make:command MyCommand` you can create a new commmand. which you can use over your cli.
How it works? I suggest that laravel iterate over some specific folders and read all files which extend the class Illuminate\Console\Command;. Then Laravel put all signature variables in an array.
Afterwards if you enter a command laravel would check the signture array with your input. Larvel would use some logics (maybe similar_text() what #GertB suggested in the comments) to find a command when you dont pass the entire command.
You are welcome to try the following. Create your own command. Enter "serv" in the signature. Then you will notice that you call your command with "php artisan serv" and no longer start the BuildIn server.
I need to run Laravel 6 application
and after running migrations I see that many tables are empty, including users.
In modules subdirectory I found files
/Modules/Users/Database/migrations/create_users_table.php
/Modules/Users/Database/seeders/UsersSeeder.php
Last file has default users
It was strange that running command
php artisan module:list
I see list of modules, but not Users module, as I expected
So I got error running in the root of my app:
php artisan module:seed Users
RuntimeException : Module [Users] does not exists.
I tried to run only this seeder, but again with error :
$ php artisan db:seed --class=/Modules/Users/Database/seeders/UsersSeeder
Illuminate\Contracts\Container\BindingResolutionException : Target class [/Modules/Users/Database/seeders/UsersSeeder] does not exist.
How can I run seeder under Users module(which I do not see in output of php artisan module:list)
?
Thanks!
If you use artisan command to make seeder
php artisan make:seeder UsersSeeder
You get the file in
database/seeds/UsersSeeder
Then you can call
php artisan db:seed --class=UsersSeeder
Instead of
php artisan db:seed --class=/Modules/Users/Database/seeders/UsersSeeder
Do not forget to run
composer dump-autoload
after first command
I just have installed voyager at laravel 5.4 and tables migrated but at the end it shows following error
Route [voyager.posts.index] not defined
As mentioned by #Muhammad Muazzam
1- Run php artisan voyager:install
However, only this didn't work for me, I needed to also
2- Clear php catch: php artisan optimize:clear
Re runing php artisan voyager:install will resolve the issue.
I am trying to make a middleware using artisan php artisan make:middleware AuthorizedUserOnly but I get ErrorException like below.
file_get_contents(/mysite.com/www/local/composer.json) Failed to open stream no such file or directory.
This is my document root.
-local
-Laravel application folders
-artisan
-index.php
-composer.json
.htaccess
I changed my directory structure to work with shared hosting. And It was working fine.
KEY NOTES
Other artisan commands work. Like I tried php artisan route:list & php artisan config:cache & php artisan tinker.
This directory structure works fine.But as the error says that it is trying to find composer.json in local directory while it is on document root.
php artisan make:model command spits the same Exception
What could be the possible issue and solution ?
Solution : I moved my composer.json file to local directory and it worked fine. So new directory structure is
-local
-Laravel Application Folders
-composer.json
-artisan
-index.php
.htaccess
HOW ?
I am not sure about this yet. But this is the possible reason. php artisan make command create some files. So to included these created files into system execute composer dump-autoload. So to run composer it looks for in the same directory where artisan lives which is local directory in my case.
IMPORTANT
I changed laravel default directory structure to successfully run my applicaiton on SHARED HOSTING which laravel DOESNOT RECOMMEND.
We should follow the recommendations made by laravel to avoid any similiar issue. Specially never to mess with default directory structure at least.
I'm trying out the PHP micro Framework Lumen (from laravel).
When I set up Lumen and I try to use the php artisan config:cache command like in Laravel, I get this error :
[InvalidArgumentException]
There are no commands defined in the "config" namespace.
So I have problem when I try to deploy the files to server, so I have to change .env file to change the database username and password.
This makes me think config is not available in artisan
How can I add it to artisan ?
Yes, you can not use the php artisan config:cache with your Lumen project, because it is not available out of the box.
You can add it by adding this package (orumad/lumen-config-cache) to your project:
composer require orumad/lumen-config-cache
In lumen you have to add this configuration in bootstrap/app.php file
$app->configure('custom_config_file_name');
#example
$app->configure('custom_emails');
Then you can access like below:
config('filename.key_name');
#example
config('constants.email');
Lumen no need to config:cache.
You do not need to do anything after change .env