How to setup Lumen in Travis CI - laravel

I have been trying to setup a Lumen application in Travis CI and i have found the following problem:
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Dotenv: Environment file .env not found or not readable.
Given that this is triggered on phpunit execution i'm trying to load my environment variables from my phpunit.xml instead of a .env file but i don't know how to make it work
Any ideas?

Your .env file should not be checked into source control and as such you dont want to use it to run builds and on production. Therefore take advantage of using Travis CI to set env variables. Refer to https://docs.travis-ci.com/user/environment-variables/.

Dotenv was developed to be used on development environments only. It always expects .env to exist and will throw an error if it doesn't.
One workaround is to check for .env and only then load Dotenv. Here's a sample piece of code that you can use.
$dotenv_var = new Dotenv\Dotenv(__DIR__);
if(file_exists(".env")) {
$dotenv_var->load();
}
You can read up more on this issue here.

Related

Laravel Telescope : error message in production logs

I use Laravel Telescope locally. It works very well.
In production, I disabled it but I noticed an error in the daily log file.
[2022-12-29 00:00:03] production.ERROR: There are no commands defined in the "telescope" namespace. {"exception":"[object] (Symfony\Component\Console\Exception\NamespaceNotFoundException(code: 0): There are no commands defined in the "telescope" namespace.
In the local log file, I don't have this message.
Thank you in advance for your help.
Delete
"laravel/telescope"
in composer.json
Looks like there's a command set to run at midnight that does something on Telescope.
Have a look at at App\Console\Kernel.php and see which commands are running at midnight.
If you need the command locally, but don't want it on production, wrap it in something like this:
if (config('app.env') === 'local') {
}

Laravel Enviroment Variables are not working within Google Cloud Run

I've deployed too many times Laravel projects up to Cloud Run successfully, but right now
It looks like Cloud Run is unable to read Enviroment Variables (which i've specified already in the Variables&Secrets section within Cloud Run instance).
I'm using Laravel 8. For testing purposes (and make sure Cloud Run it's reading env variables), i've added a simple route in the api.php section like belows:
Route::get('/test-env', function () {
echo 'debuggeando<br>';
dd(config('variables.test_env'));
});
Into my config/variables.php i've the follows:
<?php
return [
'test_env' => env('TEST_ENV', 'no se encontro la variable')
];
And this is my final result:
What do am I doing wrong? Why Cloud Run is unable to read the enviroment variables from Laravel?
You can only make Laravel pick up envirnmental variables, but not the other way around.
config(['test_env' => getenv('TEST_ENV')]);
Running php artisan config:clear & php artisan config:cache might be required. Another option might be to generate a fresh .env file during the deployment, which merely translates to: already defining the value, before it can be cached.

Unable to generate resources using laravel-code-generator in Laravel 5.8

I created a fresh Laravel project v5.8. Then installed the latest version of the Laravel Code Generator (2.3) but I'm unable to generate resources. I've read your release notes for 2.3 and I'm not seeing where I'm making a mistake on the installation or the commands I keep the output below:
php artisan create:scaffold Test generates the output below:
Exception : The file
resources/laravel-code-generator/sources/tests.json was not found!
at /Users/Sites/Laravel/lms/vendor/crestapps/laravel-code-generator/src/Models/Resource.php:686
682| {
683| $fileFullname = Config::getResourceFilePath($filename);
684|
685| if (!File::exists($fileFullname)) {
> 686| throw new Exception('The file ' . $fileFullname . ' was not found!');
687| }
688|
689| return File::get($fileFullname);
690| }
Exception trace:
1 CrestApps\CodeGenerator\Models\Resource::jsonFileContent("tests.json")
/Users/Sites/Laravel/lms/vendor/crestapps/laravel-code-generator/src/Models/Resource.php:549
2 CrestApps\CodeGenerator\Models\Resource::fromFile("tests.json", "CrestApps")
/Users/Sites/Laravel/lms/vendor/crestapps/laravel-code-generator/src/Commands/Framework/CreateScaffoldCommand.php:70
Please use the argument -v to see more details.
I'm getting a similar output when trying to create resources from a database table. I'm using the php artisan resource-file:from-database [model-name] command.
I read online that it may have to do with the Laravel storage folder not having the correct permissions but I've tried that and it didn't work. Cleared and config the cache, composer dump-autoload, etc... But nothing has worked.
I'm also noticing that the generator does not publish the configuration file on your sample video on your website. I have tried to publish the config file using the vendor:publish command but it generates a somewhat empty file, only has this option: 'files_upload_path' => 'uploads'. The folder for the generator located inside the resources folder does not contain a config file.

issue with composer when deploying using Envoyer

I'm having trouble deploying my laravel app using envoyer, the error accuer in installing composer dependencies, here it is:
Generating autoload files
Illuminate\Foundation\ComposerScripts::postInstall
php artisan optimize
[RuntimeException]
No supported encrypter found. The cipher and / or key length are invalid.
it's my first time and I'm having lots of errors and don't really know how to fix them , I'd appreciate the help thanks
You need to generate key using command php artisan generate:key
As .env is not present in production so change app.php under config file to Something like below
'key' => env('APP_KEY','base64:42KCuY7E8Zc+JHrUZFyta4yspqLAjcVZeZVvymrjZBI=')
This would solve your problem.

Artisan packages error

I'm having some trouble with artisan/packages.. I've added a package to my composer file and ran composer update and an error was returned:
PHP Warning: require(/home/xxx/public_html/bootstrap/autoload.php): failed to open stream: No such file or directory in /home/xxx/public_html/artisan on line 16
I can see that require path is incorrect, my structure is like so:
/home/xxx/bootstrap
/home/xxx/app
/home/xxx/vendor
/home/xxx/public_html
I hadn't changed any of the paths and everything seemed to work out of the box with this structure, basically removing the public folder and pushing everything up a directory.
I've opened up Artisan tried a couple of paths that kept failing so i've changed them to absolute:
require '/home/xxx/bootstrap/autoload.php';
It seemed to work from here on, but at the end of the process got another error:
Writing lock file
Generating autoload files
[RuntimeException]
Could not scan for classes inside "app/commands" which does not appear to be a file n or a folder
Rather than continue to mess it up i thought now would be a good time to clear it up, any ideas how to fix this?
Make sure you are using php 5.3 or higher.
Run php -v
Try creating an empty "app/commands" folder, fixed the issue for me!

Resources