[英]Laravel 5.8 Routed page not found 404 error
I am new to Laravel.我是 Laravel 的新手。 I am learning Laravel from tutorial and I drive into one problem which I can't solve.
我正在从教程中学习 Laravel,但遇到了一个我无法解决的问题。
I think I have problem somewhere into Routing, but I can't find it我想我在路由的某个地方有问题,但我找不到它
Funny thing is that if the href
is {{route('tag.create'}}
, then it goes to creating page, but when I need to use ID it's not working... I had same functionality for posts and categories, but everything worked fine for those two. So I really need your help to see what I can't see. I have these files:有趣的是,如果
href
是{{route('tag.create'}}
,那么它会转到创建页面,但是当我需要使用 ID 时它不起作用......我对帖子和类别具有相同的功能,但是对那两个来说一切都很好。所以我真的需要你的帮助来看看我看不到的东西。我有这些文件:
index.blade.php
: index.blade.php
:
@extends('layouts.app')
@section('content')
<div class="card">
<div class="card-body">
<table class="table table-hover">
<thead>
<th>
Tag name
</th>
<th>
Delete
</th>
</thead>
<tbody>
@if($tags->count()>0)
@foreach($tags as $tag)
<tr>
<td>
{{$tag->tag}}
</td>
<td>
<a href="{{route('tag.delete', ['id' =>$tag->id])}}" class="btn btn-danger btn-xs"><i class="fa fa-trash" aria-hidden="true"></i></a>
</td>
</tr>
@endforeach
@else
<tr>
<th colspan="5" class="text-center">
No tags yet
</th>
</tr>
@endif
</tbody>
</table>
</div>
</div>
@stop
web.php
- this is the place where I define routes for tags for TagsController.php
: web.php
- 这是我为TagsController.php
定义标签路由的地方:
//Tags
Route::get('/tags',[
'uses'=>'TagsController@index',
'as'=> 'tags'
]);
Route::post('/tag/update/{$id}',[
'uses'=>'TagsController@update',
'as'=> 'tag.update'
]);
Route::get('/tag/create',[
'uses'=>'TagsController@create',
'as'=> 'tag.create'
]);
Route::post('/tag/store',[
'uses'=>'TagsController@store',
'as'=> 'tag.store'
]);
Route::get('/tag/delete/{$id}',[
'uses'=>'TagsController@destroy',
'as'=> 'tag.delete'
]);
TagsController.php
- at first I tried to destroy the element, then I tried to return create view(because when I go through /tag/create rout everything works), but neither worked here TagsController.php
- 起初我试图销毁元素,然后我试图返回创建视图(因为当我通过 /tag/create rout 一切正常),但都没有在这里工作
public function destroy($id)
{
return view ('admin.tags.create');
/*
Tag::destroy($id);
Session::flash('success', 'Tag deleted succesfully');
return redirect()->back();*/
}
I believe that you should set the route to Route::get('/tag/delete/{id}',[ 'uses'=>'TagsController@destroy', 'as'=> 'tag.delete' ]);
我相信您应该将路由设置为
Route::get('/tag/delete/{id}',[ 'uses'=>'TagsController@destroy', 'as'=> 'tag.delete' ]);
because in your case you are telling the route to expect a variable called $id
因为在您的情况下,您告诉路由期望一个名为
$id
的变量
Please change the parameters in the route setup in web.php from $id to id.请将 web.php 中路由设置中的参数从 $id 更改为 id。 I should solve your issue.
我应该解决你的问题。
Eg: Route::get('/tag/delete/{id}',[ 'uses'=>'TagsController@destroy', 'as'=> 'tag.delete' ]);
例如:
Route::get('/tag/delete/{id}',[ 'uses'=>'TagsController@destroy', 'as'=> 'tag.delete' ]);
Thanks !!.谢谢 !!。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.