Laravel删除产品-CRUD之delete(destroy)
发布日期:2021-06-24 18:14:54 浏览次数:3 分类:技术文章

本文共 1510 字,大约阅读时间需要 5 分钟。

  上一篇讲了,现在我们讲一下删除产品,方法和前面的几篇文章类似,照着ytkah来操作吧

  1,controller的function destroy定义,注意这里的Name是destroy(),文件在/app/Http/Controllers/ItemController.php

public function destroy($id)    {        $item = Item::find($id);        $item->delete();    }

  2,模板的编辑,有两个地方,show.blade.php和index.blade.php,用<input type="hidden" name="_method" value="DELETE">的方法

show.blade.php模板修改

@extends('layouts.app')@section('content')    
Item:{
{$item->id}}
{ {$item->id}}
{ {$item->name}}
{ {$item->price}}
{ {$item->description}}
{ {$item->created_at}}
{ {$item->updated_at}}
@csrf
@endsection

  index.blade.php模板修改

@extends('layouts.app')@section('content')
List of Items
@foreach($items as $item)
@endforeach
# Name Price Img description Created At Update At Actions
{ {$item->id}} { {$item->name}} { {$item->price}} { {$item->img}} { {$item->description}} { {$item->created_at}} { {$item->updated_at}} view
@csrf
{ {$items->links()}}
Create New Item
@endsection

  

 

转载地址:https://blog.csdn.net/weixin_34248258/article/details/86131507 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:bootstrap课程13 bootstrap的官方文档中有一些控件的使用有bug,如何解决这个问题...
下一篇:SVN 命令行的使用

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月10日 07时50分05秒