Alexxosipov
Alexxosipov

Reputation: 1234

Laravel service provider does not see the main class of my package

I got the service provider and my class for shopping cart.

This is my service provider:

<?php

namespace Alexxosipov\Cart;

use Illuminate\Support\ServiceProvider;
use Alexxosipov\Cart\Cart as Cart;

class CartServiceProvider extends ServiceProvider {
    public function boot() {

    }

    public function register() {
        $this->app->singleton('cart', function() {
            return new Cart;
        });
    }
}

but my phpstorm says me, that use Alexxosipov\Cart\Cart as Cart; is never used in code. Where did I go wrong?

Upvotes: 0

Views: 39

Answers (1)

user3647971
user3647971

Reputation: 1056

According to laravel documentation, you need to type hint the Cart interface:

<?php

namespace Alexxosipov\Cart;

use Illuminate\Support\ServiceProvider;
use Alexxosipov\Cart\Cart as Cart;

class CartServiceProvider extends ServiceProvider {
    public function boot() {

    }

    public function register() {
        $this->app->singleton(Cart::class, function() {
            return new Cart;
        });
    }
}

Upvotes: 1

Related Questions