Laravel方法在href链接? [英] laravel method in href link?
问题描述
我想用两个链接创建一个下拉列表。 删除和修改链接。
I want to create a dropdown with two links. A 'Delete' and a 'Edit' link.
对于删除功能,我创建了一个表单。
For the delete function I created a form.
{!! Former::horizontal_open()->method('DELETE')->action(action("Test\\TestController@destroythread", $comment->id)) !!}
{!! Former::danger_submit('Delete') !!}
{!! Former::close() !!}
表单工作,这意味着我的评论被删除,如果我按下按钮。
The form works, that means my comment get's deleted, if I'm pressing the button.
不,我决定删除删除按钮,并使用删除链接进行下拉列表。所以我需要在我的下拉菜单中获得这个表单的逻辑。
No I decided to remove the delete button and do a dropdown with a delete link. So I need to get the logic of this form in my dropdown menu.
但我没有在下拉列表中。光标删除按钮是下拉菜单的这一部分:
But I haven't got this in the dropdown.. The optical 'Delete' button is this part of the dropdown:
<li><a href="#">
Delete
</a></li>
但是我不能把我的控制器功能放在href-link中,因为没有'DELETE' - 方法,它不会工作。我希望你们都明白我想说的话...我的英文不是最好的。
But I can't just put my controller function in that "href-link", cause without the 'DELETE'-Method, it won't work. I hope you all understand what I'm trying to say... my english isn't the best anyway.
有人可以帮我吗?
感谢您的帮助!
我以前尝试过,但这还没有工作: / p>
I tried it like this before but this haven't worked either:
<li>
<a>
{!! Former::horizontal_open()->method('DELETE')->action(action("Test\\TestController@destroythread", $comment->id)) !!}
Delete
{!! Former::close() !!}
</a>
</li>
我尝试直接链接到路线:
my try linking directly to the route:
<li><a href="{{ route('destroy', $comment->id) }}">Delete</a></li>
,我的路线如下所示:
Route::delete('/show/{id}', 'Test\\TestController@destroythread')->name('destroythread');
但这没有为我工作..
but this haven't worked for me..
all / show / routes:
all /show/ routes:
Route::get('/show/{id}', 'Test\\TestController@show');
Route::put('/show/{id}/edit', ['as' => 'editing', 'uses' => 'Test\\TestController@update']);
Route::get('/show/{id}/edit', 'Test\\TestController@edit')->name('edit');
Route::delete('/show/{id}', 'Test\\TestController@destroy')->name('destroy');
Route::delete('/show/{id}', 'Test\\TestController@destroythread')->name('destroythread'); // this is the route we are talking about
推荐答案
替代方式,尝试' Laravel Collective 'Html Helper。
Alternative way, try 'Laravel Collective' Html Helper.
HTML
{!! Form::open('delete',
'method' => 'delete,
'route' => ['show.destroy', $comment->id]
) !!}
{!! Form::submit('Submit') !!}
{!! Form::close() !!}
routes.php
Route::delete('show/{show}', [
'uses' => 'TestController@destroy',
'as' => 'show.destroy'
]);
这篇关于Laravel方法在href链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!