Ad

Namespace Issue In Model In Laravel - Package Development

- 1 answer

I am developing a package in laravel which uses model for CRUD operations.

I have put it up in packagist as well, but when I try to install it in laravel application and visit a route defined by the package, it says

Class 'Zusamarehan\Tourify\Model\Tourifies' not found

The following is the folder structure of my package

  • rehan
    • tourify
      • src
        • assets
        • database
        • Http
        • Model
          • Tourifies.php
        • resources
        • routes
        • TourifyServiceProvider.php
        • composer.json

The following is the contents of my Tourifies.php

<?php
namespace Zusamarehan\Tourify\Model;

use Illuminate\Database\Eloquent\Model;

class Tourifies extends Model
{

}

The following is my composer.json file

{
    "name": "zusamarehan/tourify",
    "description": "A Package for adding Tour/Help to your Laravel Projects.",
    "keywords": ["laravel", "tour", "tourify", "product-tour", "product-help"],
    "type": "library",
    "license": "MIT",
    "authors": [
        {
            "name": "zusamarehan",
            "email": "[email protected]"
        }
    ],
    "minimum-stability": "dev",
    "require": {
        "php": ">=5.3.0"
    },
    "extra": {
        "laravel": {
            "providers": [
                "Zusamarehan\\tourify\\TourifyServiceProvider"
            ]
        }
    },
    "autoload": {
        "psr-4": {
            "Zusamarehan\\tourify\\": "src"
        }
    }
}

The Model class is not loading I suppose? I am not sure.

Can someone point out the mistake?

Ad

Answer

"Zusamarehan\\tourify\\": "src" in your composer.json is wrong. Needs uppercase T. Looking at mine I also have a trailing / after src so you can try that as well. You have the same lowercase t in the provider.

Ad
source: stackoverflow.com
Ad