一、下载 laravel 5.4
composer create-project laravel/laravel=5.4.* laravel5.4_facades
切换目录
cd laravel5.4_facades
二、facades
启动服务
php artisan serve
新建 app/Services/Weibo.php
namespace App\Services;
class Weibo
{
protected $http;
public function __construct(Http $http)
{
$this->http = $http;
}
public function publish($status)
{
$this->http->post($status);
}
}
新建 app/Services/Http.php
namespace App\Services;
class Http
{
public function post($status)
{
dd('I posted as status :'. $status);
}
}
修改 routes/web.php
use Facades\App\Services\Weibo;
Route::get('/', function () {
Weibo::publish('这是一条微博');
});