Laravel Backpack Admin CRUD Views返回404

时间:2017-11-14 22:52:57

标签: backpack-for-laravel

我有一个在本地开发环境中工作,但现在我正在推动它我遇到了一个错误:

当我尝试访问我的CRUD页面(/ admin / images或类似网页)时,我会被带到我的网站404页面。

我上传了/routes/admin.php文件,我的所有资源文件,控制器,模型,供应商文件,公共/供应商文件,以及其他一些我忘记提及的内容。

不确定背包的配置文件中是否有东西我需要编辑或是什么。寻找一些方向。

注意:我可以从Backpack(仪表板,登录,注销)

访问默认路由

RouteServiceProvider.php

protected function mapWebRoutes()
{
    Route::middleware('web')
         ->namespace($this->namespace)
         ->group(base_path('routes/web.php'));
}

protected function mapApiRoutes()
{
    Route::prefix('api')
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));
}

protected function mapAdminRoutes()
{
    Route::middleware(['web', 'admin'])
         ->prefix('admin') // or use the prefix from CRUD config
         ->namespace($this->namespace.'\Admin')
         ->group(base_path('routes/admin.php'));
}

在错误日志中发现此错误:

  

异常'Illuminate \ Database \ Eloquent \ RelationNotFoundException'   消息'在模型上调用未定义的关系[轮子]   [应用\模型\ WheelFinishes]“。在   laravel /框架/ SRC /照亮/数据库/锋/ RelationNotFoundException.php:20

但我在 WheelFinishes模型

中定义了关系
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;

class WheelFinishes extends Model
{
    use CrudTrait;

    public function wheels()
    {
        return $this->belongsTo('App\Models\Wheels', 'wheel_id');
    }

    ...
}

车轮型号     

namespace App\Models;

use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
use App\User;

class Wheels extends Model
{
use CrudTrait;

protected $table = "wheels";
protected $primaryKey = 'id';

...

public function tips()
{
    return $this->hasMany('App\Models\WheelTips', 'wheel_id');
}

public function finishes()
{
    return $this->hasMany('App\Models\WheelFinishes', 'wheel_id')->where('status', '=', '1')->orderBy('order');
}

public function factoryFinishes()
{
    return $this->hasMany('App\Models\WheelFinishes', 'wheel_id')->where('status', '=', '1')->where('factory_finish', '=', '1')->orderBy('order');
}

public function wheelImages()
{
    return $this->hasMany('App\Models\WheelImages', 'wheel_id');
}

public function wheelImage()
{
    return $this->hasOne('App\Models\WheelFinishes', 'wheel_id')->where('status', '=', '1')->orderBy('order');
}

public function profile()
{
    return $this->BelongsTo('App\Models\Profile');
}

public function series()
{
    return $this->BelongsTo('App\Models\Series');
}

public function vehicles()
{
    return $this->hasMany('App\Models\Vehicles', 'wheel_id')->where('status', '=', '1')->orderBy('order')->take(3);
}

public function vehicle()
{
    return $this->hasOne('App\Models\Vehicles', 'wheel_id')->where('status', '=', '1')->orderBy('order');
}

}

routes.php文件

<?php

// Backpack\CRUD: Define the resources for the entities you want to CRUD.
CRUD::resource('video', 'VideoCrudController');
CRUD::resource('wheels', 'WheelCrudController');
Route::get('finishes/ajax-finishes-options', 'FinishCrudController@wheelsOptions');
CRUD::resource('finishes', 'FinishCrudController');
Route::get('albums/ajax-albums-options', 'AlbumCrudController@albumsOptions');
CRUD::resource('albums', 'AlbumCrudController');
CRUD::resource('heros', 'HeroCrudController');

1 个答案:

答案 0 :(得分:0)

如果你有一个单独的路径文件,你可能需要在RouteServiceProvider中注册它:

    Route::group([
        'middleware' => 'web',
        'namespace' => $this->namespace,
    ], function ($router) {
        require base_path('routes/web.php');
        require base_path('routes/admin.php');
    });