First you need to go to the app/config/app.php and add to providers :
'Laracms\Providers\SettingsServiceProvider',
In the same file in the aliases section you should add:
'Settings' => 'Laracms\Facades\Settings',
In app/Laracms/Providers you must create the SettingsServiceProvider.php file
<?php namespace Laracms\Providers; use Illuminate\Support\ServiceProvider; class SettingsServiceProvider extends ServiceProvider { public function register() { $this->app->bind('settings', function() { return new \Laracms\Settings(); }); } }
In app/Laracms/Facades/ you must create the Settings.php file:
<?php namespace Laracms\Facades; use Illuminate\Support\Facades\Facade; class Settings extends Facade { protected static function getFacadeAccessor() { return 'settings'; } }
Now in your app/Laracms you should create the Settings.php file:
<?php namespace Laracms; class Settings { public function get() {echo "get"; } public function set() {echo "set"; } }
Since you wanted to have your files in the Laracms user folder, you need to add this folder to your composer.json (if you used the standard app/models folder, you would not need to add anything to this file). So now open the composer.json file and in the autoload โ classmap you should add app/Laracms so that this composer.json section looks like this:
"autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php", "app/Laracms" ] },
Now you need to start the console inside your project:
composer dump-autoload
to create a class map
If everything is in order, now you can use Settings::get() and Settings:set() in your applications
You should notice that I used folders with upper strings because namespaces by convention begin with uppercase letters.