Created
October 29, 2013 16:13
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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