laravel 的背包 - Guzzle 实例错误
Backpack for laravel - Guzzle instance error
我正在为 laravel 使用背包,当我尝试初始化网络时我的一个模块给我一个错误 api class (Guzzle)...我有此代码:
控制器
class ImportacionesCrudController extends CrudController
{
protected $api;
public function setup(webApi $api) {
$this->api = $api;
dd($this->api->sendValidation());
}
}
它实例化了这个class:
namespace app\Api;
use GuzzleHttp\Client;
class webApi
{
protected cliente;
function __construct()
{
#Se inicializa la conecccion al servicio web
$client = new Client([
// Base URI is used with relative requests
'base_uri' => 'https://jsonplaceholder.typicode.com',
// You can set any number of default request options.
'timeout' => 2.0,
]);
$this->cliente = $client;
#dd($response->getBody()->getContents());
}
public function sendValidation(){
return $this->cliente->request('GET', 'posts');
}
}
它给我这个错误:
Declaration of App\Http\Controllers\Admin\ImportacionesCrudController::setup(App\Api\webApi $api) should be compatible with Backpack\CRUD\app\Http\Controllers\CrudController::setup()
知道哪里出了问题吗?谢谢你的时间。
您不能覆盖 setUp
方法并添加参数,因为父 class 在该方法中不接受参数。但是,您可以在构造函数中执行此操作:
class ImportacionesCrudController extends CrudController
{
private $api;
public function __construct(webApi $api) {
$this->api = $api;
return parent::__construct();
}
public function setUp()
{
$this->api->sendValidation();
....
我正在为 laravel 使用背包,当我尝试初始化网络时我的一个模块给我一个错误 api class (Guzzle)...我有此代码:
控制器
class ImportacionesCrudController extends CrudController
{
protected $api;
public function setup(webApi $api) {
$this->api = $api;
dd($this->api->sendValidation());
}
}
它实例化了这个class:
namespace app\Api;
use GuzzleHttp\Client;
class webApi
{
protected cliente;
function __construct()
{
#Se inicializa la conecccion al servicio web
$client = new Client([
// Base URI is used with relative requests
'base_uri' => 'https://jsonplaceholder.typicode.com',
// You can set any number of default request options.
'timeout' => 2.0,
]);
$this->cliente = $client;
#dd($response->getBody()->getContents());
}
public function sendValidation(){
return $this->cliente->request('GET', 'posts');
}
}
它给我这个错误:
Declaration of App\Http\Controllers\Admin\ImportacionesCrudController::setup(App\Api\webApi $api) should be compatible with Backpack\CRUD\app\Http\Controllers\CrudController::setup()
知道哪里出了问题吗?谢谢你的时间。
您不能覆盖 setUp
方法并添加参数,因为父 class 在该方法中不接受参数。但是,您可以在构造函数中执行此操作:
class ImportacionesCrudController extends CrudController
{
private $api;
public function __construct(webApi $api) {
$this->api = $api;
return parent::__construct();
}
public function setUp()
{
$this->api->sendValidation();
....