Laravel5.1 form deletion operation

Source: Internet
Author: User
Laravel5.1 two ways to delete an operation form

1. Form operations

Laravel is required to install laravelcollective

"require": {"php": ">=5.5.9","laravel/framework": "5.1.*","laravelcollective/html": "5.1.*"},

You can use {!! Form: open ()!!} Tag
As follows:

{!! Form: open (array ('URL' => route ('admin. shop_category_tag.destroy ', $ shop_category_tag-> id), 'method' => 'Delete '))!!} {!! Form: submit ('delete', array ('class' => 'btn btn-info btn-danger '))!!} {!! Form: close ()!!}

If not installed

Use the default HTML form to submit and delete the file. for example:


The controller method can be written as follows:

Public function destroy ($ id) {$ shop_category_tag = Shop_category_tag: find ($ id); if ($ shop_category_tag-> delete () {return Redirect: back () -> with ('message', 'deleted successfully! ');} Else {return Redirect: back ()-> withInput ()-> with ('errors', 'deletion failed! ');}}

Route:

Route::resource('shop_category_tag','ShopCategoryTagController');

2. new controller methodDelete ()

The controller content is the same as the preceding one. However, you must note that you need to add a delete () method for the route, which will increase the complexity of the route. The second method is not recommended here.

Address: http://note.mango.im/article/8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.