mysql - how to do delete of particular row from a table in laravel 5.2 -


i created 1 view page, there displaying data in table fetching database. , given action drop down . 2 options there in drop down. view/edit , delete. when select edit button, corresponding row should delete database. how can write code in laravel?. in normal php know. can 1 write code??. view page given below

  @extends('app')  @section('content')       <div class="templatemo-content-wrapper" xmlns="http://www.w3.org/1999/html">         <ol class="breadcrumb">             <li><a href="{{ url("/") }}"><font color="green">home</font></a></li>             <li class="active">user information</li>         </ol>         <div class="templatemo-content">              <h1>view/edit user information</h1>              <div>                 <div>                     <div>                          <table id="example" class="table table-striped table-hover table-bordered" bgcolor="#fff8dc">                             <h3>select user :</h3>                             <thead>                             <tr>                                 <th>user id</th>                                 <th>user desc</th>                                 <th>contact name</th>                                 <th>contact email</th>                                 <th>time zone</th>                                 <th>active</th>                                 <th>last login (gmt+05:30)</th>                                 <th>actions</th>                             </tr>                             </thead>                             <tbody>                              {{--{{ usercontroller::getindex() }}--}}                             @foreach($name $nam)                                 <tr>                                     <td>{{ $nam->userid }}</td>                                     <td>{{ $nam->description }}</td>                                     <td>{{ $nam->contactname }}</td>                                     <td>{{ $nam->contactphone }}</td>                                     <td>{{ $nam->timezone }}</td>                                     <td>                                         @if($nam->isactive == '1')                                             yes                                             @else                                         no                                             @endif                                     </td>                                     <td>{{ date('y/m/d h:i:s',($nam->lastlogintime)) }}</td>                                     <td>                                         {{--@if ( in_array($nam->isactive, array('yes','no')) )--}}                                              <div class="btn-group">                                                 <button type="button" class="btn btn-info">action</button>                                                 <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">                                                     <span class="caret"></span>                                                     <span class="sr-only">toggle dropdown</span>                                                 </button>                                                 <ul class="dropdown-menu" role="menu">                                                     {{--@if ($nam->isactive == 'yes')--}}                                                         <li data-toggle="modal" data-target="#acceptmodal" data-bookingid="{{ $nam->userid }}"><a href="#">view/ edit</a>                                                         </li>                                                     {{--@endif--}}                                                     <li><a href="{{ url('/user/delete/'.$nam->userid)}}">delete</a></li>                                                 </ul>                                             </div>                                         {{--@endif--}}                                     </td>                                 </tr>                             @endforeach                             </tbody>                         </table>                         {{$name->links()}}                     </div>                 </div>             </div>         </div>     </div>                  <input type="submit" id="submit" name="submit" value="view" class="button">     <a href="{{ url('user/add') }}"> <input type="submit" id="add" name="add" value="edit" class="button"></a>                  </br>         <h4>create new user</h4>     {{--<form class="templatemo-preferences-form" role="form" method="post" action="{{ action('usercontroller@save') }}">--}}         {{--<input type="hidden" name="_token" value="{{ csrf_token() }}">--}}      <form role="form" method="post" action="{{ url('useradmin') }}">         <input type="hidden" name="_token" value="{{ csrf_token() }}">           <div class="row">             <div class="col-md-6 margin-bottom-15">                  <input type="text" class="form-control" name="userid" value="{{ old('userid') }}" placeholder="enter user id">             </div>             <div class="row templatemo-form-buttons">                 <div class="submit-button">                     <button type="submit" class="btn btn-primary">new</button>                  </div>             </div>             </div>     </form> {{--</form>--}}       <script type="text/javascript">         $(document).ready(function() {             $('#example').datatable();         } );     </script> @endsection 

controller page is

    <?php namespace app\http\controllers; use mail; use illuminate\support\facades\db; use faker\provider\datetime; use app\user; use app\http\requests\createuserrequest; use illuminate\support\facades\auth; use illuminate\support\facades\validator; use illuminate\support\facades\input; use symfony\component\httpfoundation\request;  class usercontroller extends controller {     public $type = 'user';   public function getindex()     {          $name = db::table('user')->simplepaginate(10);         return view('user.useradmin')->with('name', $name);     }      public function getdata()     {          $name = db::table('user');         return view('user.add')->with('name', $name);     }      public function userinsert()     {         $postuser = input::all();         //insert data mysql table         $data =      array('userid'=> $postuser['userid']         );         //  echo print_r($data);         $ck = 0;         $ck = db::table('user')->insert($data);         //echo "record added successfully!";         $name = db::table('user')->simplepaginate(10);         return view('user.useradmin')->with('name', $name);       }      public function delete($id)     {         $user = bookings::find($id);         $user->status = 'not confirmed';         $user->save();          $currusr = user::find($user->userid);           return redirect('useradmin');     }   } 

please me this...

simply following delete record specific records...

public function delete($id) {     db::table('user')->where('userid', '=', $id)->delete();     return redirect('useradmin'); } 

happy coding!!!


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -