vendredi 27 novembre 2015

Update with Laravel and ajax

Hello everybody iam new to laravel and i hope you will help me to solve this problem. I want to update a particular column conditions, 1 to 0 and 0 to 1 when user click the link with Ajax. I have column named status which can have value 1 or 0,according to user click the link value gets updated.

I have two route

 Route::get('/logo/updateY/{id}', [ 'uses'=> 'Backend\Logo\LogoController@updateYesStatus', 'permission'=> 'update' ]);
 Route::get('/logo/updateN/{id}', [ 'uses'=> 'Backend\Logo\LogoController@updateNoStatus', 'permission'=> 'update' ]);

controller

public function updateYesStatus($id)
  {
     $logoStatus = Logo::findOrFail($id);
     $logoStatus->update(['status'=>'1']);
     return redirect::to('administrator/logo/view');

  }
  public function updateNoStatus($id)
  {
     $logoStatus = Logo::findOrFail($id);
     $logoStatus->update(['status'=>'0']);
     return redirect::to('administrator/logo/view');

  }

view:

@if($logo->status== 1)
  <td ><a  href="{{url('/administrator/logo/updateN',[$logo->id])}}" class="label label-success userStatus"id="{{$logo->id}}">Displayed</a></td>
  @else
 <td ><a href="{{url('/administrator/logo/updateY',[$logo->id])}}" class="label label-danger userStatus" id="{{$logo->id}}">Hidden</a></td>
   @endif</td>





<script type="text/javascript">
    $(document).on('click','.userStatus',function(){
        var id = $(this).attr('id');
        $.ajax({
            data:{ id=id, _token: '{!! crfs_toekn() !!}'},
            url: '',
            type: 'POST',
            dataType: 'json'

            success:function()
            {

            }
       });
    });


</script>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire