I want to select all data from 1 table in command prompt (not from browser) using Laravel framework. Is there anyone know what the good references is? please give me link, thankyou
You can create an Artisan Command.
Check the Laravel 5.0 docs:
http://laravel.com/docs/5.0/commands
Then, you can run you command. Example:
php artisan mycommand:list
Laravel 4.2:
http://laravel.com/docs/4.2/commands
You can run artisan commands from "cmd" (Windows). (Edit your environment variables first! Add you PHP path).
Try:
php artisan tinker
Then:
DB::table('users')->get()
Related
I need to run this command when user change something in translation file
php artisan export:messages-flat
I need to add it in may controller
so I'm using this code
\Artisan::call('export:messages-flat');
but it return error saying that
The command "export:messages-flat" does not exist.
but when I
php artisan list
it's in the list
I also try to run other command
\Artisan::call('cache:clear');
and it works
this is the package I'm using link
kindly help me, sorry for may poor english
The package only allows you to run the commands from the CLI. You can see from the source code, they only register the Artisan commands if the application is running from the console.
As an alternative, you can call ExportLocalization::export()->toFlat() according to their documentation.
I'm running php artisan tinker followed by App\Project::all(); but upon pressing enter, I just get redirected to my project directory as opposed to displaying all records in the database?
What am I doing wrong and how can I fix it?
I have php 7.3 on my machine installed via homebrew.
I have to add a config file.
nano ~/.config/psysh/config.php
<?php return [ 'usePcntl' => false,]; ?>
After doing this I am able to use tinker
Please remove the App.
Project::all()
Can you try this.
I'd like to create a php script which connects to a mysql server, makes changes on a database and runs a php artisan command.
The first part I have figured out (mysql connection) but is it possible to just put (for example):
php artisan snipeit:ldap-sync --location_id=1
into my script and it will run the command, or am I missing something here?
I'd appreciate it if you could send me into the right direction wtih this. Thank you.
You can use Artisan::call().
Artisan:call('snipeit:ldap-sync', [
'--location_id' => 1
]);
It can also take a second parameter to specify an array of command parameters.
For more information, see Programmatically Executing Commands.
You can call artisan command from code like this:
Artisan::call('cache:clear');
I'm trying to write a command as a quickstart to build a project. The command asks for input for database details and then changes the .env file. The problem is that the command needs to do some Database queries afterwards, but the .env variables are not reloaded.
My question would be, is there a way to reload or override .env variables runtime. And if not, is there a way to call another Artisan command freshly, so framework bootstraps again?
In my command I tried doing $this->call('build:project') in my actual command, but even in the second call the variables are not reloaded.
Is there a way to achieve this without making the user manually call multiple commands?
Thanks!
i had the same problem with reloaded .env variables, and i fixed it with this command line which allow you to clear the configuration :
php artisan config:clear
Hope that helped. Regards.
Laravel uses config files which take data from .env file. So, what you can do is to override configuration values at runtime:
config(['database.default' => 'mysql']);
Try to clear cache it helped me (couldn't ssh into the server)
Is there a {app route}/bootstrap/cache/config.php file on the production server? Delete it.
This helped me
As OP I'm trying to bootstrap a Laravel project build by running console command and asking for the database credentials in the middle of the process.
This is a tricky problem and nothing I read was able to fix it : reset config, cache, Dotenv reload, etc... It seems that once the console command / operation is initialized the initial database connection is kept all over until the end.
The working solution I found is to bypass, after database modification are done, this cached state by using native shell exec command and passing the php artisan command as parameter :
passthru('php artisan migrate');
So, the order will be :
php artisan project:build (or whatever is your console command)
prompt the user for database credentials
replace values in .env file (your search & replace algorythm)
run php artisan config:cache
passthru('php artisan migrate'); ro run your migrations
shell_exec would do the same but in silent mode while passthru will return the output generated by console.
https://www.php.net/manual/en/function.passthru.php
Done successfully on Laravel 8.52
I clone my project from gitlab and I make it on my new computer.
But I get nothing ouput after I run php artisan migrate and the corresponding table is not created.
Output of php artisan migrate:status below.
What the meaning of "Ran?" and why status my migration file are all "N". php artisan migrate will create these tables successfully only when the "Ran?"s are "Y"?
An Y in the Ran column means the migration has been done.
Check your .ENV file , make sure your database settings are correct, also make sure you actually created the database beforehand.
clear the entire laravel cache to stay up to date with current .env settings, it might help.
try using php artisan migrate:refresh sometime it happens with me and i find out it's already migrated