Skip to content

Instantly share code, notes, and snippets.

@patrickcurl
Created October 29, 2013 16:13
Show Gist options
  • Save patrickcurl/7217712 to your computer and use it in GitHub Desktop.
Save patrickcurl/7217712 to your computer and use it in GitHub Desktop.
What am I missing to get this to update db on click of link?
// Just the js that's included in my blade template using JS extension for syntax highlighting.
$('#processed').on('click', 'a.process', function(e){
e.preventDefault();
var id = ($this).data('id');
var bool = ($this).data('bool');
var url = "{{URL::to('/api/v1/sorders/')}}" + "/" + id;
$.ajax({
url: url,
type: 'patch',
dataType: 'json',
data: { processed : bool },
success: function(ev){
console.log(ev);
},
error: function(hxr, error, status){ alert('Error'); }
});
});
// this is in a for loop ...
<td id="order">
<input type="checkbox" class="processed" data-id="{{$o->id}}" @if($o->processed == true) checked="checked" @endif disabled="disabled" />
<a href="#" class="yes" data-id="{{$o->id}}" data-bool="true">Yes</a> |
<a href="#" class="no" data-id="{{$o->id}}" data-bool="false">no</a>
</td>
<?php
namespace api;
use Illuminate\Support\Facades\View;
use Illuminate\Routing\Controllers\Controller;
class SupplyOrdersController extends \Controller {
protected static $restful = true;
public function update($id){
$order = \SupplyOrder::find($id);
$checked = \Request::get('processed');
if(isset($checked) && $checked == "true" ){
$order->processed = true;
$order->save();
return \Response::json(array(
'error' => false,
'processed' => true),
200
);
} else {
$order->processed = 0;
$order->save();
return \Response::json(array(
'error' => false,
'processed' => false),
200
);
}
return \Response::json(array(
'error' => true,
'processed' => false),
200
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment