Laravel - settings depending on environment - laravel

I just started using Laravel and now I'm configuring my application. I want different settings for my local and production environment and read the Laravel 5.2 docs on the best way to do that. But I can't figure out how to do this for all the config files. For example I want the session.secure setting to be false on local and true on production. What is the best way to do that?
In the index.php file I do a check if (App::environment('local')) and if that is false I update the session.secure to true -> config(['session.secure' => true]).
I update the /config/session.php file and set 'secure' => false to 'secure' => env('SESSION_SECURE', false). And then I make two .env-files (one for local and one for production) with the variable SESSION_SECURE and the corresponding values.
Is there another/better way?
Thank you!

The common way is to set the settings in your .env file. So you change the value of 'secure' to your .env key e.g
'secure' => env('SECURE', false),
In your .env file on your production server, just set the .env value SECURE to true.
SECURE=true
So with this in your local Environment, the 'secure' setting is set to false as default. And if you are on your production Server, just set the .env Key to true and the 'secure' configuration changes also from false to true.
You may also have a look at this .env Article for Laravel

Related

how to change database configs in laravel?

My larave app have setup steps.
In the database configuration step, user inputs should be placed as database configuration, but i dont know how can i set custom configs for database.
I used this code, but it changes the configs temporarily and doesn't save them.
Config::set("database.connections.mysql", [
"host" => "...host...",
"database" => "...database...",
"username" => "...username...",
"password" => "...password..."
]);
Just try to change .env file or on config/database.php do your corrections

How to disable Redis in Laravel for dev version

I have a Laravel API that I need to test locally. How can I disable Redis cache on a local Laravel server? I can't disable it manually deleting all Redis::connection cases.
You can change "Default Cache Store" in config/cache.php file in your project.
By default you should have this 'default' => env('CACHE_DRIVER', 'file'),
You have a few solutions depending on what you have there:
if you already have changed default cache driver on that file, just change it to 'file' (not recommended!)
better would be change to default value 'default' => env('CACHE_DRIVER', 'file'), but add appropriate value in .env file CACHE_DRIVER=file

How to change Laravel 5 sessions to redis

I now set a lot of values to the session using Session::put and Session::get. If I want to use Redis throughout the application, is it true that I just need to replace all Session:: with Redis:: to make it work?
By the way, I already installed the Redis package
All you have to do is just changing your .env file :
SESSION_DRIVER=redis
and use Session::get() etc.
You should change in connfig/session.php 'driver' => env('SESSION_DRIVER', 'file'), file to redis.

Bypass Cache when in Dev Environment

Case scenario:
$dbResult = myEloquentClass::remember(60)->all();
My results are being cached, which works great for a production environment.
However, i am finding myself removing the remember method in my development environment since i don't want to cache my database results.
This results in a lot of unnecessary removal/additions of code.
Is there a way to bypass the cache globally for eloquent's remember when in development environment?
In laravel - 4 edit the app/config/local/cache.php file and set the driver to array.
<?php
return array(
'driver' => 'array',
);
For laravel 5 - edit the .env file and set the CACHE_DRIVER to array
CACHE_DRIVER=array
As posted by #bogdan,
I switch my development cache.php config file's driver to array, and works as advertised.

How do you set default engine for the Schema Builder?

How can you set a default engine when using migrations (Schema Builder)? I recently got place on a shared hosting and their default MySQL engine is MyISAM. Instead of having to rewrite all my migration files to include $table->engine = 'InnoDB' I'm wondering if you can set this as default.
Is it possible?
I don't think it is,the docs http://laravel.com/docs/schema#storage-engines. Can't find any other mentioning of db engine in the docs.
You would expect it to be possible in app/config/database.php
I manage to do it. I'm using Laravel 5.5. In the config/database.php:
'connections' => [
'mysql' => [
...
'engine' => env('DB_ENGINE', null)
],
As you may know this will fetch the DB_ENGINE var from en .env file.
So in that file I setted like this:
DB_ENGINE=MyISAM
It will work if you set the var to InnoDB also.

Resources