Example not working with Laravel 9
Closed this issue · 1 comments
italo1983 commented
I'm unable to make the example code working with Laravel 9.
Adding MyModel::setApi($this->app->make(CustomWrapper::class));
to the AppServiceProvider boot function generate the error:
Class "App\MyModel" not found
I've created the MyModel.php file inside the app/Http/Models folder with the example code:
<?php
namespace App;
use Cristal\ApiWrapper\Bridges\Laravel\Model;
class MyModel extends Model
{
// Nothing here
}
and also a wrapper inside app/Wrappers folder:
<?php
namespace App;
use Cristal\ApiWrapper\Api;
class CustomWrapper extends Api
{
// Nothing here...
}
and this is the content of my provider:
<?php
namespace App\Providers;
use App\MyModel;
use App\CustomWrapper;
use Illuminate\Support\ServiceProvider;
use Cristal\ApiWrapper\Transports\Basic;
use Curl\Curl;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(): void
{
MyModel::setApi($this->app->make(CustomWrapper::class));
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(CustomWrapper::class, function(){
$transport = new Basic(
'username',
'password',
'http://api.example.com/v1/',
$this->app->make(Curl::class)
);
return new CustomWrapper($transport);
});
}
}
TZK- commented
Your classes are not following PSR-4 so composer cannot autoload these in your project.
That must be why you have PHP errors. It is not related to php-api-wrapper.