douya2982 2016-09-05 14:20
浏览 28
已采纳

为什么数据不会删除Laravel 5.3?

I am trying to delete data from data information, but it is not deleting. is there any solution ? The deleting button is just below the edit button. And the destroy function is in the infoController.php

Index.blade.php

 <!DOCTYPE html>
<html>
<head>
    <title>All userinfo</title>
<link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

</head>
<body>

<div class="container">
    <div class="row col-md-6 col-md-offset-2 custyle">

    <table class="table table-striped custab">
    <thead>
    <a href="userinfo/create" class="btn btn-primary btn-xs pull-right"><b>+</b> Add new categories</a>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Email</th>
            <th>Age</th>
            <th>Hometown</th>
            <th class="text-center">Action</th>
        </tr>
    </thead>

    @foreach($alldata as $data)

            <tr>
                <td>{{ $data -> id }}</td>
                <td>{{ $data -> name }}</td>
                <td>{{ $data -> email }}</td>
                <td>{{ $data -> age }}</td>
                <td>{{ $data -> hometown }}</td>

                <td class="text-center"><a class='btn btn-info btn-xs' style="margin-bottom:5px" href="{{route('userinfo.edit',$data->id)}}"><span class="glyphicon glyphicon-edit"></span> Edit</a> 

                <a href="{{route('userinfo.destroy',$data->id)}}" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-remove"></span> Delete</a></td>
            </tr>

           @endforeach

    </table>

  {!! $alldata -> render(); !!}

    </div>
</div>

</body>
</html>

infoController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\infomodel;

class infoController extends Controller
{

 public function index()

 {


   $alldata = infomodel::paginate(4);

   return view('userinfo.index', compact('alldata'));


 }


 public function create()

 {


return view('userinfo.create');


 }


 public function store(Request $request)

 {

    $input = $request->all();

    infomodel:: create($input);

    return redirect('userinfo');


 }

 public function show ()

 {


 }


 public function edit($id)
 {


  $updateinfo = infomodel::findorfail($id);

  return view('userinfo.edit', compact('updateinfo'));



 }


 public function update(Request $request, $id)

 {

     $input = $request -> all();

     $data = infomodel::findorfail($id);

     $data -> update($input);

     return redirect('userinfo');



 }



 public function destroy ($id)

 {

     $data = infomodel::findorfail($id);

     $data -> delete();

     return redirect('userinfo');

 }




}

Routes/web.php

<?php


Route::resource('userinfo','infoController');


Route::get('/solid', function () {
    return view('solid.index');
});
  • 写回答

1条回答 默认 最新

  • douchai7891 2016-09-05 14:24
    关注

    You're using resource controller, so you'll need to use Delete method, for example:

    {!! Form::open(['method' => 'Delete', 'route' => ['someroute.destroy', $id]) !!}
        <button type="submit">Delete</button>
    {!! Form::close() !!}
    

    Or, you should use additional Get route:

    Route::get('delete/{id}', 'MyController@deleteInfo');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建