dphnn333971 2017-10-20 15:33
浏览 676
已采纳

PHP警告:include(C:\ xampp \ htdocs \ hse \ vendor \ composer /../../ app / Buildings.php):无法打开流

I've previously manually deleted some models files in App* and created other with just removing the "s" symbol as because laravel by default can recognise the models from there name , and models by Laravel standadrd must be written normal not in plural.

Before deleting the models that i created them using php artisan make:model Buildings -m

The new model i created after i removed the (buildings) model is php artisan make:model Building Notice that i just created a new model without 's'

Now in my User model i have created method :

public function UserAssignedBuilding(){
        return $this->hasManyThrough('App\Building','App\Area','user_id','area_id');
    }

Building.php Model file

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Building extends Model
{
    protected $table = 'buildings';

    public function areas(){
        $this->belongsTo('App\Area');
    }

}

Area.php Model file:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Area extends Model
{
    protected $fillable = [
        'name'
    ];

    public function users(){
        return $this->belongsToMany('App\User','area_user','area_id','user_id');
    }

    public function buildings(){
        return $this->hasMany('App\Building');
    }
}

In php artisan when i run the following command, to get the user assigned buildings:

>>> User::find(4)->UserAssignedBuilding
PHP warning:  include(C:\xampp\htdocs\hse\vendor\composer/../../app/Buildings.php): failed to open stream: No such file or directory in C:\xampp\htdocs\hse\vendor\composer\ClassLoader.php on line 444

It seems that the error is the framework trying to load the (Buildings.php) model file, which i had already delete it and created (Building.php) instead .

I run the following :

C:\xampp\htdocs\hse>composer dumpautoload
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Package manifest generated successfully.

But issue not fixed

Also tried to get buildings rows, other error showing:-

>>> Building::all()
PHP Fatal error:  Class 'Building' not found in eval()'d code on line 1
  • 写回答

3条回答 默认 最新

  • dongwu8064 2017-10-20 16:14
    关注

    In your command you are missing model namespace

    It should be

    App\User::find(4)->UserAssignedBuilding
    

    And

    App\Building::all()
    

    Also change method UserAssignedBuilding to buildings

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 脱敏项目合作,ner需求合作
  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴