D
D
David2016-06-15 13:07:30
Laravel
David, 2016-06-15 13:07:30

What am I doing wrong? Laravel 5 service provider?

config/app.php:

...
'providers' => [
       ...
        App\Providers\CustomRegisterProvider::class,
    ],

File app/Providers/CustomRegisterProvider:
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Services\CustomRegister;

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

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind('App\Services\CustomRegisterContract', function(){
            return new CustomRegister();
        });
    }
}

In controller:
...
use App\Services\CustomRegister as Register;

class RegisterController extends Controller
{
...

/**
     *  Регистрация потребителя
     *
     * @param Request $request
     */
    public function consumer(Request $request, Register $register){
       ...
    }
}

Mistake:
ReflectionException in Route.php line 286:
Class App\Services\CustomRegister does not exist

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2016-06-15
@Denormalization

App\Services\CustomRegisterContract is bound and App\Services\CustomRegister is injected . Logic not working?
You need to inject App\Services\CustomRegisterContract

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question