am developing one php application using laravel. in that when i trying to pass value from view to controller using ajax call. am having a issue in routing this is my code in routing
Route::post('AssetdetailsController/postPositions/{id}', array('as'=>'post_form','uses' => 'Controllers\Admin\AssetdetailsController@postPosition'));
am trying to pass the route value in javascript alert am getting an empty alert box.
This is my ajax call
$(document).ready(function() {
$('#asset_type_id').change(function() {
// alert($('#asset_type_id option:selected').val());
var id = $('#asset_type_id option:selected').val();
$.ajax({
type: 'POST',
url: '{{ URL::route('post_form') }}',
data: id,
cache: false,
success: function(data)
{
alert(data);
check(data);
},
error: function(xhr, textStatus, thrownError) {
alert('Something went to wrong.Please Try again later...');
}
});
});
});
This is my controller
public function postPosition($id) {
$positions = DB::table('asset_types')->where('id', '=', $id )->pluck('is_nesd');
return $positions;
}
I tried like this to check the value that i am getting in id through alert box
public function postPosition($id) {
return $id;
}
I got output as {id} in alert box.
I also tried passing a value manually in query instead of ${id} and iam getting the correct output
public function postPosition($id) {
$positions = DB::table('asset_types')->where('id', '=', 1 )->pluck('is_nesd');
return $positions;
}
So now my question is how get the value of ${id} correctly from view.
Hi i finally get the answer what i did is
In ajax function my old code is
url: '{{ URL::route('post_form') }}',
And i changed to
url: '{{ action("postPositions", " ") }}'+id,
This one working correctly