Lumen 5.3: Set php artisan environment - php

How can I set environment variable of a php artisan command using Lumen 5.3? Laravel 5.0 says:
php artisan migrate --env=local
But in newer version documentations this section is disappeared. I run this my command like:
php artisan myCommand --env=testing
But both in my command class and bootstrap file (simply everywhere) dumping env(APP_ENV) results in local
Any suggestions?

It's as simple as
APP_ENV="production" php artisan myCommand
Or in multiple environment as
APP_ENV="production" DB_USER="foo" DB_PASSWORD="bar" php artisan myCommand

Related

.env can't get read from inside a job

I have a Laravel project (v8.12) running on PHP 7.4.3 in a dedicated AWS instance with Ubuntu 20.04. When I try to read an environment variable from inside a job, the value is always null, but it works elsewhere. I tried to switch from supervisord to sync driver, still couldn't reach it.
Your problem could be from cache .
you can below commands for remove cache .
php artisan cache:clear
php artisan config:clear
php artisan view:clear
Run below commands
composer dump-autoload
php artisan clear-compiled
php artisan optimize
php artisan route:clear
php artisan view:clear
php artisan cache:clear
php artisan config:cache
php artisan config:clear
For Example
In your env file
SITE_NAME="My website"
Get your env variable like
$data = env('SITE_NAME');
echo $data;

Lumen 5.6 php artisan migrate --env=testing not working

Lumen Version: 5.6
PHP Version: 7.2
Database Driver & Version: SQLite 3
Steps To Reproduce:
cp .env .env.testing
SetAPP_ENV=testing
Run php artisan migrate --env=testing
Problem
Old env file configuration is executing.
First:
php artisan cache:clear
php artisan config:cache
You need to specify the environment before the migrate command.
php artisan --env=testing migrate
I found the solution myself. This feature is not there in this lumen version.
PR LINK FIX

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.

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

Categories