Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel binding not working

Tags:

php

laravel

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
like image 601
Jamie Avatar asked Oct 31 '22 11:10

Jamie


1 Answers

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.

like image 87
patricus Avatar answered Nov 15 '22 07:11

patricus