laravel 服务容器的用法

建立一个服务

<?php
namespace App\Services;
class FooService
{
    public function __construct(){

    }

    public function  doSomething(){
        echo "some";
    }
}

  

绑定服务

$this->app->bind('\App\Services\FooService');


在控制器里调用
$fooService = app()->make('\App\Services\FooService');
$fooService->doSomething();

posted on 2019-11-14 11:12  小V_chen  阅读(816)  评论(0编辑  收藏  举报

导航