php - How to delete a certain object from your list in Laravel? -
i have subscribers table :
when click on delete btn bring modal confirm :
i'm close, when hit delete, keep delete last 1 on list if i'm not pressing last delete btn.
i know have use {!! form::hidden('$id', $subscribe->id)!!}
somewhere, i'm not sure should place it.
table
<?php $x = 0; ?> <div class="container"> <div class="row"> <a href="subscribe/create" class="btn btn-sm btn-success "> <span class="fa fa-plus"></span> create </a><br><br> <table class="table"> {{--table header--}} <thead class="thin-border-bottom"> <th width="50" >#</th> <th width="200" >email</th> <th width="100" >subscribe on </th> <th width="100" >delete </th> </thead> {{--table body--}} <tbody> <tr> @foreach( $subscribes $subscribe) <?php $x = $x+1; ?> <td>{{ $x }}</td> <td>{{ $subscribe->email or '' }}</td> <td>{{ $subscribe->created_at or '' }}</td> <td><a data-toggle="modal" data-target="#delete_subscriber" type="button" class="btn btn-danger btn-xs">delete</a></td> </tr> @endforeach </tbody> </table> </div> </div>
modal
<div class="modal fade" id="delete_subscriber" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true"> <div class=" col-lg-5"> </div> <div class=" center col-lg-2"> {!! form::model($subscribe, array( 'route' => array('subscribe.destroy', $subscribe->id),'method' => 'delete')) !!} <hr style="height:300pt; visibility:hidden;" /> {!! form::submit ('delete subscriber', array('class'=> 'btn btn-danger btn-lg btn-block', 'data-rel'=>"tooltip" , 'title'=>"are sure ?", 'data-placement'=>"top"))!!}<br><br> <button data-rel="tooltip" title="go back" data-placement="bottom" type="button" class="btn btn-primary btn-lg btn-block" class="close" data-dismiss="modal" > cancel </button> <br> {!! form::hidden('$id', $subscribe->id)!!} {!! form::close()!!} </div> </div>
can please show me, how can delete right 1 ?
how can stop application delete last object in list ?
controller
public function destroy($id){ $subscribe = subscribe::find($id); $subscribe->delete(); return redirect::to('subscribe') ->with('success','the web directory deleted succesfully!'); }
i had same problem , because in hurry had bypass problem creating new modal every record inside foreach loop in view . don't think sophisticated solution in case, expected small number of records due pagination, worked fine. suppose use jquery manipulate modal action on every click couldn't make work. hope helps
Comments
Post a Comment