【问题标题】:Base table or view not found when using routes使用路由时找不到基表或视图
【发布时间】:2019-11-15 07:28:59
【问题描述】:

我正在做的网站的管理方面存在问题。我在管理端包含了 4 个链接,但是当我点击其中任何一个时,我都会收到此错误:

SQLSTATE[42S02]: 未找到基表或视图:1146 表 'sonic.admins' 不存在(SQL: select * from admins where id = peripherals limit 1)

我不知道那个 SQL 查询来自哪里,因为据我所知,我没有运行任何查询

我使用以下控制器作为一个断开链接的示例:

Route::resource('/admin/games', 'AdminGamesController', ['names'=>[
  'index'=>'games.index',
  'create'=>'games.create',
  'store'=>'games.store',
  'edit'=>'games.edit',
  'show'=>'games.show',
  'destroy'=>'games.destroy',
  ]]);

但是

Route::resource('/admin', 'AdminController', ['names'=>[
  'index'=>'admin.index',
  'create'=>'admin.create',
  'store'=>'admin.store',
  'edit'=>'admin.edit',
  'show'=>'admin.show',
  'destroy'=>'admin.destroy',
  ]]);

工作正常。

这是我用于上述示例路由的控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AdminGamesController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return 'test';
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

这里是链接

<div class="list-group list-group-flush">
  <a href="{{route('home.index')}}" class="list-group-item list-group-item-action"><i class="fas fa-home"></i>&nbsp;&nbsp;Home</a>
  <a href="{{route('games.index')}}" class="list-group-item list-group-item-action"><i class="fas fa-home"></i>&nbsp;&nbsp;Games</a>
  <a href="{{route('figures.index')}}" class="list-group-item list-group-item-action"><i class="fas fa-user-friends"></i>&nbsp;&nbsp;Figures</a>
  <a href="{{route('guides.index')}}" class="list-group-item list-group-item-action"><i class="fas fa-user-friends"></i>&nbsp;&nbsp;Guides</a>
  <a href="{{route('peripherals.index')}}" class="list-group-item list-group-item-action"><i class="fas fa-user-tie"></i>&nbsp;&nbsp;Peripherals</a>
</div>

【问题讨论】:

  • 我认为问题出在您的身份验证/访客检查中间件之一。
  • 我删除了中间件,但它仍然在这样做
  • 在 storage/logs/ 中查找堆栈跟踪,看看它是从哪里发生的。
  • 我没有看到任何明显的东西
  • 视图/布局中可能有一些帮助?

标签: php sql laravel laravel-5.8


【解决方案1】:

问题:路线相互冲突/重叠

admin/{admin}  // This is admin route URL
admin/games    // and this is from admin games route URL

Route::group([
    'prefix' => 'admins',  // Here we need to do something different
    'as'     => 'admin.'
],function () {
    Route::resource('admin','AdminController');
});
// http://localhost/project_name/public/admins/admin
Route::group([
    'prefix' => 'admin',
    'as'     => 'admin.'
],function () {
    Route::resource('games','AdminGamesController');
});

// http://localhost/awsupload/public/admin/games

这是我在我的路线中尝试过的仅适用于管理游戏的方法,并且运行良好

Route::group([
    'prefix' => 'admin',
    'as'     => 'admin.'
],function () {
    Route::resource('games','AdminGamesController');
});

在刀片文件中,游戏路线可通过以下刀片语法访问:

    // Games Listing
    {{route('admin.games.index')}}

    // Save game to the database
    {{route('admin.games.store')}}

    // Create Game form/page
    {{route('admin.games.create')}}

    // Show single game details
    {{route('admin.games.show',['game_id'])}}

    // Show edit form for single game
    {{route('admin.games.edit',['game_id'])}}

    // Update single game details
    {{route('admin.games.update',['game_id'])}}

    // Remove/Delete single game
    {{route('admin.games.destroy',['game_id'])}}

【讨论】:

    猜你喜欢
    • 2015-11-19
    • 2023-04-01
    • 1970-01-01
    • 2019-01-28
    • 2017-08-02
    • 2023-03-08
    • 1970-01-01
    • 2015-12-23
    相关资源
    最近更新 更多