gpt4 book ai didi

php - 使用路由时找不到基表或 View

转载 作者:搜寻专家 更新时间:2023-10-31 21:47:12 26 4
gpt4 key购买 nike

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

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sonic.admins' doesn't exist (SQL: select * from admins where id = peripherals limit 1)

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

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

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',
]]);

工作正常。

这是我用于上述示例路由的 Controller :

<?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>

最佳答案

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

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 仅针对管理游戏尝试过的方法,并且运行良好

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

enter image description here

在 Blade 文件中,游戏路径可以通过以下 Blade 语法访问:

    // 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'])}}

关于php - 使用路由时找不到基表或 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56889908/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com