Ad

Laravel Binding Not Working

- 1 answer

I'm using the laravel service container today for the first time. I know there is a lot to find on the internet about it but I can't find a solution for it. I'm trying to bind an interface to a class but when I do this I receive the error:

Target [App\contracts\UploadService] is not instantiable.

This is my service container called UploadServiceContainer:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;


class UploadServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind('App\Contracts\UploadService', 'App\Classes\upload\upload');
    }

}

I try to instantiate it like this in my controller:

public function storeTicket(makeTicketRequest $request,UploadService $upload)
{ }

I've registered my Serviceprovider in app.php. And I've also done:

php artisan clear-compiled
Ad

Answer

In your call to bind(), you're using App\Contracts\UploadService (capital "Contracts"), but the error message states App\contracts\UploadService (lower "contracts"). Correct the discrepancy and it should work.

Ad
source: stackoverflow.com
Ad