Casey
Casey

Reputation: 560

Laravel Backpack Admin CRUD Views returning 404

I had this working on a local dev environment, but now that I'm pushing it live I'm running into an error:

When I try to access my CRUD pages (/admin/images or similar), I get taken to my websites 404 page.

I uploaded the /routes/admin.php file, all my resource files, controllers, models, vendor files, public/vendor files, and probably some others I'm forgetting to mention.

Not sure if theres something in the config files for backpack I need to edit or what. Looking for some direction.

Note: I am able to access the default routes from Backpack (dashboard, login, logout)

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

Found this error in the error logs:

exception 'Illuminate\Database\Eloquent\RelationNotFoundException' with message 'Call to undefined relationship [wheels] on model [App\Models\WheelFinishes].' in laravel/framework/src/Illuminate/Database/Eloquent/RelationNotFoundException.php:20

But I have the relationship defined in my 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');

Upvotes: 0

Views: 2902

Answers (1)

Jeff
Jeff

Reputation: 25221

If you have a separate route file you probably need to register it in RouteServiceProvider:

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

Upvotes: 0

Related Questions