我有一个Laravel-5.8项目,如下所示:
控制器:Admin / LeavesController
use App\Models\Leave;
class LeavesController extends Controller
{
public function leave_review()
{
try {
$leaves = Leave::get();
return view('admin.leaves.leave_review')
->with(['leaves', $leaves);
} catch (Exception $exception) {
Session::flash('error', 'Action failed! Please try again');
return back();
}
}
route / web.php
Route::group(['prefix' => 'admin', 'as' => 'admin.', 'namespace' => 'Admin', 'middleware' => ['auth']], function () {
Route::get('admin/leaves/leave_review', 'LeavesController@leave_review')->name('leaves.leave_review');
});
视图文件夹是这样的:
views-> admin-> leaves-> leave_review.blade.php
布局/边栏:
<li class="nav-item">
<a href="{{ route("admin.leaves.leave_review") }}" class="nav-link {{ request()->is('admin.leaves') || request()->is('admin.leaves/*') ? 'active' : '' }}">
<i class="far fa-circle nav-icon"></i>
<p>
<span>Leave-Review</span>
</p>
</a>
我有我的php artisan route:list
| GET | HEAD | admin / admin / leaves / leave_review | admin.leaves.leave_review | App \ Http \ Controllers \ Admin \ LeavesController @ self_review |网络,身份验证|
当我渲染页面时,尽管页面已加载,但是在路线admin中重复了两次:
即admin / admin
当我删除管理员前缀并以这种方式发送路由时:
因此将其从您的路线中删除,将其更改为此
Route::group(['prefix' => 'admin', 'as' => 'admin.', 'namespace' => 'Admin', 'middleware' => ['auth']], function () {
Route::get('leaves/leave_review', 'LeavesController@leave_review')->name('leaves.leave_review');
});
我遇到另一个错误:
找不到错误404页面,并且uri更改为:
为什么以及如何纠正呢?
谢谢
答案 0 :(得分:0)
因为现在您的路线是 admin / leaves / leave_review ,而不是 admin / admin / leaves / leave_review 。
如果您经常更改路线链接,则可以考虑在视图内将路线名称用作 route('leaves.leave_review')。这样,如果名称未更改,您将始终获得与该名称关联的路由。