简体   繁体   English

Model 中的命名空间问题 Laravel - Package 开发

[英]Namespace issue in Model in Laravel - Package Development

I am developing a package in laravel which uses model for CRUD operations.我正在 laravel 中开发laravel ,它使用 model 进行 CRUD 操作。

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我也把它放在了packagist中,但是当我尝试在 laravel 应用程序中安装它并访问由 package 定义的路由时,它说

Class 'Zusamarehan\Tourify\Model\Tourifies' not found Class 'Zusamarehan\Tourify\Model\Tourifies' 未找到

The following is the folder structure of my package下面是我的package的文件夹结构

  • rehan热汗
    • tourify旅游化
      • src源代码
        • assets资产
        • database数据库
        • Http Http
        • Model Model
          • Tourifies.php Tourifies.php
        • resources资源
        • routes路线
        • TourifyServiceProvider.php TourifyServiceProvider.php
        • composer.json作曲家.json

The following is the contents of my Tourifies.php以下是我Tourifies的内容Tourifies.php

<?php
namespace Zusamarehan\Tourify\Model;

use Illuminate\Database\Eloquent\Model;

class Tourifies extends Model
{

}

The following is my composer.json file以下是我的composer.json文件

{
    "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": "zrehan286@gmail.com"
        }
    ],
    "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?我想 Model class 没有加载? I am not sure.我不知道。

Can someone point out the mistake?有人可以指出错误吗?

The namespaces in your classes use Zusamarehan\Tourify , however, in your composer.json you've used Zusamarehan\tourify .您的类中的命名空间使用Zusamarehan\Tourify ,但是,在您的composer.json中,您使用Zusamarehan\tourify These should match.这些应该匹配。

You'll need to update your composer.json file so that the namespaces uses the correct case:您需要更新您的composer.json文件,以便命名空间使用正确的大小写:

{
    "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": "zrehan286@gmail.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {
        "php": ">=5.3.0"
    },
    "extra": {
        "laravel": {
            "providers": [
                "Zusamarehan\\Tourify\\TourifyServiceProvider"
            ]
        }
    },
    "autoload": {
        "psr-4": {
            "Zusamarehan\\Tourify\\": "src"
        }
    }
}

"Zusamarehan\\tourify\\": "src" in your composer.json is wrong. "Zusamarehan\\tourify\\": "src"在您的composer.json中。json 是错误的。 Needs uppercase T .需要大写T Looking at mine I also have a trailing / after src so you can try that as well.看看我的,我在src之后也有一个尾随/ ,所以你也可以试试。 You have the same lowercase t in the provider.您在提供程序中有相同的小写t

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM