首页 文章

Laravel Backpack Admin CRUD Views返回404

提问于
浏览
0

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

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

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

Not sure if theres something in the config files for backpack I need to edit or what. 寻找一些方向 .

注意:我可以从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',消息'调用模型[App \ Models \ WheelFinishes]上的未定义关系[wheels] . 在laravel / framework / src / Illuminate / Database / Eloquent / RelationNotFoundException.php:20

但我在 WheelFinishes model 中定义了这种关系

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');
    }

    ...
}

Wheels Model

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

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

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

相关问题