S_R
S_R

Reputation: 1998

Where to put global php in Laravel application

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?

Upvotes: 0

Views: 555

Answers (1)

Olim Saidov
Olim Saidov

Reputation: 2844

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)

Upvotes: 2

Related Questions