Store data through Repository - Not working



  • I'm having trouble with this error -

    *Illuminate \ Contracts \ Container \BindingResolutionException
    Target [Webkul\Brand\Contracts\Brand] is not instantiable while building 
    [Webkul\Brand\Http\Controllers\BrandController].*
    

    I was trying to create new package. Using direct model & controller is fine and working but when I was trying repositories,contracts & proxies I get this error.

    [N.B : I implement the Brand (Contracts) in my Brand (Model)]



  • Hi,

    Please make sure that you have created 'ModuleServiceProvider.php' file in your package & mentioned all of your model here. Like -

    <?php

    namespace Webkul\Attribute\Providers;

    use Konekt\Concord\BaseModuleServiceProvider;

    class ModuleServiceProvider extends BaseModuleServiceProvider
    {
    protected $models = [
    \Webkul\Attribute\Models\Attribute::class,
    ...
    ];
    }

    after doing it, in config folder you can see there is a 'concord.php' file, mention this provider there like -
    return [
    'modules' => [
    VendorA\ModuleX\Providers\ModuleServiceProvider::class,
    VendorB\ModuleY\Providers\ModuleServiceProvider::class
    ]
    ];

    for more reference, please see any of our package.

    Thanks
    Rahul Shukla



  • Do I have to create "concord.php" in my newly created package?
    If so, then I already created "concord.php" and added modules but error still there. I was trying to use your Category module as reference.



  • No, you don't need to create it, it will be in config folder, see there and do whatever i mentioned above.



  • Capture.PNG

    Still getting error...

    Capture.PNG

    And the other problem is Whenever I run these commands

    php artisan config:clear
    php artisan cache:clear
    php artisan route:cache
    php artisan view:clear
    composer dump-autoload
    php artisan vendor:publish
    

    This error occurs

    Capture2.PNG

    Then command solves the error

    php artisan config:cache


  • run 'php artisan migrate' to solve above error.



  • It says Nothing to migrate.



  • Make sure that you have implemented or extended contract on your model like -

    <?php

    namespace Webkul\Attribute\Models;

    use Webkul\Core\Eloquent\TranslatableModel;
    use Webkul\Attribute\Contracts\Attribute as AttributeContract;

    class Attribute extends TranslatableModel implements AttributeContract
    {

    }

    In the above example, you can see that Attribute model is implementing its contract AttributeContract and i think you are missing this.
    after this please run -
    php artisan config:clear
    php artisan cache:clear
    php artisan key:generate
    composer dump-autoload



  • Capture3.PNG



  • Capture4.PNG


Log in to reply