【发布时间】:2019-03-16 05:23:30
【问题描述】:
我是 Laravel 的新手。我正在从教程中学习 Laravel,但遇到了一个我无法解决的问题。
我认为我在路由的某个地方有问题,但我找不到它
有趣的是,如果href 是{{route('tag.create'}},那么它会去创建页面,但是当我需要使用 ID 时它不起作用......
我对帖子和类别有相同的功能,但对这两者来说一切都很好。所以我真的需要你的帮助才能看到我看不到的东西。我有这些文件:
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 - 这是我为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 - 起初我试图破坏元素,然后我试图返回创建视图(因为当我通过 /tag/create rout 时一切正常),但在这里都没有工作
public function destroy($id)
{
return view ('admin.tags.create');
/*
Tag::destroy($id);
Session::flash('success', 'Tag deleted succesfully');
return redirect()->back();*/
}
【问题讨论】:
-
将
{$id}更改为{id}。