3

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?

2 Answers 2

2

The namespaces in your classes use Zusamarehan\Tourify, however, in your composer.json you've used Zusamarehan\tourify. These should match.

You'll need to update your composer.json file so that the namespaces uses the correct case:

{
    "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"
        }
    }
}

Sign up to request clarification or add additional context in comments.

1 Comment

Let me try and get back
1

"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.

2 Comments

Let me try this and get pack. Btw, where to look up your composer file?
You can pretty much look up any package. First one in my history, github.com/spatie/laravel-feed/blob/master/composer.json#L45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.