I am taking my first steps in Laravel 5, specifically with package development. My purpose with this package is to be booted in every single request, always.
So, I started creating the service HelloWorldServiceProvider:
<?php
namespace FacebookKiller\Modules\HelloWorld;
use Illuminate\Support\ServiceProvider;
class HelloWorldServiceProvider extends ServiceProvider{
protected $defer = false;
public function boot(){
dd('hello world at boot()')
}
public function register()
{
dd('hello world at register()')
}
}
Actually, this file is this path from root:
/Larave/app/Modules/HelloWorld/HelloWorldServiceProvider.php
Then, I edit the config/app.php file in order to add the service provider
'Illuminate\Translation\TranslationServiceProvider',
'Illuminate\Validation\ValidationServiceProvider',
// my module
'FacebookKiller\Modules\HelloWorld\HelloWorldServiceProvider'
Finally, in order to test if dd() is called, I have edited the routes.php file like:
Route::get('test', function(){
return "Making a test request";
});
The result is negative. The Service provider is not loaded. According to docs:
Deferring the loading of such a provider will improve the performance of your application, since it is not loaded from the filesystem on every request. To defer the loading of a provider, set the defer property to true
So, I make the opposite setting protected $defer to false. But the dd() function is not triggered.
It is important to use Service Provider type because by that way I could load lang, views and config files from it.