Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm getting this BindingResolutionException in Laravel #20

Closed
llevvi opened this issue Jan 9, 2017 · 1 comment
Closed

I'm getting this BindingResolutionException in Laravel #20

llevvi opened this issue Jan 9, 2017 · 1 comment

Comments

@llevvi
Copy link
Contributor

llevvi commented Jan 9, 2017

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.

@llevvi
Copy link
Contributor Author

llevvi commented Jan 9, 2017

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.

@llevvi llevvi closed this as completed Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant