Service Providers
Service providers are the central place for all Yuga application service registering.
php yuga make:provider LogServiceProviderLast updated
Service providers are the central place for all Yuga application service registering.
php yuga make:provider LogServiceProviderLast updated
<?php
namespace App\Providers;
use App\Models\User;
use Yuga\Providers\ServiceProvider;
use Yuga\Interfaces\Application\Application;
class TestServiceProvider extends ServiceProvider
{
/**
* Register bindings in the container.
*
* @return void
*/
public function load(Application $app)
{
$app->singleton('my-users', function ($app) {
return User::all();
});
}
}<?php
// for a controller
namespace App\Controllers;
use Yuga\Controllers\Controller as BaseController;
class UserController extends BaseController
{
public function __construct()
{
parent::__construct();
}
public function users($app)
{
$users = $app->make('my-users');
// or
$users = $app['my-users'];
}
}<?php
//for a view-model
namespace App\ViewModels;
class Test extends App
{
/**
* Load or / manupulate data when its a get request
*/
public function onGet()
{
$users = app()->make('my-users');
// or
$users = app()['my-users');
}
}