建立一個目錄叫services
建立一個weibo類php
<?php
namespace App\Services;
class weibo
{
protected $http;post
public function __construct(Http $http) { $this->http = $http; } public function publish($status){ $this->http->post($status); }
}this
建立一個Http類spa
<?php namespace App\Services; class Http { public function __construct() { } public function post($status){ return dd('I post a post'.$status); } }
路由修改code
use Facades\App\Services\weibo; //facade Route::get('facade',function (){ weibo::publish('這是一條微博'); });
如今訪問就有了:"I post a post這是一條微博"路由