0

Sorry if this is a silly question or has been answered before, but I just need a quick bit of advice!

Where is the best place in a Laravel 5 application to apply global php settings and why?

For example, if I want to set

ini_set('max_input_vars','10000');

and other various code that will be set globally across the application, where is best practise put it?

Please can someone properly explain where and why?

S_R
  • 1,818
  • 4
  • 27
  • 63
  • This is what you have you .env file for - https://laravel.com/docs/5.6/configuration – Niels Jul 30 '18 at 11:09
  • @Niels but how do I actually run something like an `ini_set` function in the `.env` file? – S_R Jul 30 '18 at 11:12
  • 1
    You don't, ideally you don't use ini_set and directly change it in your .ini itself. If you really need to do it like this the best practice is to write a middleware for that does this. – Niels Jul 30 '18 at 11:14

1 Answers1

2

Answer to the first question

No need to create a middleware for this. Middlewares are useful when you want to do something based in the request you receive or the response you are returning. But you want to just set php config value globally on every request. So, you can just create a new file in /bootstrap folder naming php_config.php, write there all ini_set calls and require this file in /public/index.php file.

Answer to the second question

So if you want to run some arbitrary piece of code to run on every request and you can create a middleware or a singleton service. The latter is useful when you need to reference to the result of the executed code (i.e. api call to third-part service)

Olim Saidov
  • 2,796
  • 1
  • 25
  • 32
  • It doesn't error out, but if i set `ini_set('max_input_vars','10000');` in my new `php_config` file and then run `{{ini_get('max_input_vars')}}` it is not showing the new value? I am including the new file like so `require_once __DIR__.'/../bootstrap/php_config.php';` – S_R Jul 30 '18 at 11:29
  • Ahh nevermind, I've just realised that `max_input_vars` is not allowed to be changed using the `ini_set` method anything. Thanks for your help! – S_R Jul 30 '18 at 11:35
  • Make sure that the php configuration of your web-server allows you to change configs via ini_set. – Olim Saidov Jul 30 '18 at 11:37
  • 1
    According to https://stackoverflow.com/questions/9973555/setting-max-input-vars-php-ini-directive-using-ini-set/9973738, I dont think it makes a difference, `max_input_vars` cant be edited via `ini_set` – S_R Jul 30 '18 at 11:38
  • @S_R I’ve also updated my answer for the second question. – Olim Saidov Jul 30 '18 at 11:39