I'm getting this BindingResolutionException in Laravel
llevvi opened this issue · 1 comments
Hello,
This is probably not an issue in the optimus class itself. I must be doing something silly or forgetting to do something.
I have this controller called "VendorsControllers" where I inject Optimus in the constructor. When I try to go to the index page I get this:
BindingResolutionException in Container.php line 850:
Unresolvable dependency resolving [Parameter #0 [ <required> $prime ]] in class Jenssegers\Optimus\Optimus
Here's an snippet of my controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Vendor;
use Auth;
use Jenssegers\Optimus\Optimus;
class VendorController extends Controller
{
protected $optimus;
public function __construct(Optimus $opt)
{
$this->optimus = $opt;
}
public function index()
{
$user = Auth::user();
$vendors = Vendor::with('user')->get();
foreach($vendors as $key => $vendor){
$vendor->id = $this->optimus->encode($vendor->id);
$vendors[$key] = $vendor;
}
return view('vendors/index', compact('vendors'));
}
And here's my Optimus service provider:
<?php
namespace App\Providers;
use Jenssegers\Optimus\Optimus;
use Illuminate\Support\ServiceProvider;
class OptimusServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(Optimus::class, function ($app) {
return new Optimus(2123809381, 1885413229, 146808189);
});
}
}
Should I register this service provider? I wasn't sure if it was really needed since Optimus documentation doesn't mention that.
Thanks in advance.
Well, the issue was what I suspected. The service provider has to be added to the providers array in config/app.php:
App\Providers\OptimusServiceProvider::class,
Sorry, I should've tested this before I opened the issue. At least it will be registered here for those who make the same mistake in the future. I'm also gonna do a pull request to include it on your documentation.