没有找到laravel的课程?

时间:2017-01-04 06:56:30

标签: php laravel

今天我正在尝试修复以下错误。它告诉我一些奇怪的原因,我在拉拉维尔的关系的阶级不存在?我不确定为什么因为代码看起来对我很好。

Class 'App\Database\Website\Roleplay\GovermentRole' not found

发生的地方:

{{ $governmentMember->government_role->government_title }}

完整代码:

@if ($higherGovernment->count() > 0)
    @foreach ($higherGovernment as $governmentMember)
    <div class="col-md-10">
        <div class="col-md-12" style="margin-left:-40px;">
            <div class="col-md-1" style="margin-top:-16px;"><img src="http://mywebsite.com/images/get_character_look.php?look={{ $governmentMember->user->look }}&size=b&direction=3&head_direction=3"></div>
            <div class="col-md-9" style="margin-left:40px;">
                <h4>{{ $governmentMember->government_role->government_title }}<small>The Crown</small></h4>
                <p><font color="#aaa">Department here</font></p><br>
            </div>
        </div>
    </div>
    @endforeach
@else
    There are currently no candigates working in this category.
@endif

这是我的Roleplay Stat类,$ governmentMember是一个实例:

<?php
namespace App\Database\Website\User;

use Eloquent;

class Roleplay extends Eloquent
{
    protected $primaryKey   = 'id';
    protected $table        = 'srp_user_statistics';
    public $timestamps      = false;
    protected $fillable     = [];

    public function user()
    {
        return $this->belongsTo('App\Database\Website\User\Player', 'user_id', 'id');
    }

    public function government_role()
    {
        return $this->belongsTo('App\Database\Website\Roleplay\GovermentRole', 'government_id');
    }
}

这是我的GovernmentRole类:

<?php

namespace App\Database\Website\Roleplay;

use Eloquent;

class GovernmentRole extends Eloquent
{
    protected $primaryKey   = 'id';
    protected $table        = 'srp_government_roles';
    public $timestamps      = false;
    protected $fillable     = [];

    public function stats(){
       return $this->hasMany('App\Database\Website\User\Roleplay', 'government_id');
   }
}

以下是刀片页面的控制器:

<?php

namespace App\Http\Controllers\Frontend\User;

use Auth;
use Cache;
use Illuminate\Http\Request;
use App\Database\Website\User\Roleplay;
use App\Database\Website\Roleplay\GovernmentRole;
use App\Database\Website\Roleplay\Life\LifeEvents;

class GovernmentController
{
    public function getView()
    {
        $royalty = Cache::remember('government.royalty', 1, function() {
            return GovernmentRole::where('government_type', 'royalty')->first()->stats;
        });

        $higherGovernment = Cache::remember('government.higher_government', 1, function() {
            return GovernmentRole::where('government_type', 'higher_government')->first()->stats;
        });

        $seniorGovernment = Cache::remember('government.senior_government', 1, function() {
            return GovernmentRole::where('government_type', 'senior_ministers')->first()->stats;
        });

        $juniorGovernment = Cache::remember('government.junior_government', 1, function() {
            return GovernmentRole::where('government_type', 'junior_ministers')->first()->stats;
        });

        return view('frontend.community.government', compact('juniorGovernment', 'seniorGovernment', 'higherGovernment', 'royalty'));
    }
}

3 个答案:

答案 0 :(得分:0)

错误是因为 GovermentRole 文件在指定路径不可用,即

App\Database\Website\Roleplay\GovermentRole

答案 1 :(得分:0)

确保班级位于正确的文件夹中。然后运行以下命令:

composer dumpauto

答案 2 :(得分:0)

很抱歉告诉你这个,但是输入错误&#39;在你的关系方法

public function government_role()        
{
  return $this->belongsTo('App\Database\Website\Roleplay\GovermentRole', 'government_id');
}

您正在寻找&#39; GovermentRole&#39;而班级&#39;名字是&#39; GovernmentRole&#39;。注意额外的&#39; n&#39; &#39; r&#39;

之后的角色