i got NotFoundHttpException when i am trying to get data using ajax request method "post"
here is routes (web.php)
Route::prefix('shoppingcart')->group(function() {
Route::middleware(['auth','roles:1,2,3'])->group(function () {
Route::get('/', 'ShoppingCartController@index')->name('shoppingcart');
Route::get('/create', 'ShoppingCartController@create')->name('shoppingcart.create');
Route::post('/store', 'ShoppingCartController@store')->name('shoppingcart.store');
Route::post('/getProducts/{id}', 'ShoppingCartController@getProducts');
});
});
controller
public function getProducts($id){
$data['products'] = DB::table('products')
->join('entity_localizations' , 'entity_localizations.item_id', '=', 'products.id')
->select('products.id as id',
DB::raw('coalesce((entity_localizations.value),products.name) as name'),'products.price as price')
->where('entity_localizations.entity_id', '=', Helper::getEntityId("Product")->id)
->where('products.product_department_id', '=', $id)
->get();
return $data;
}
index.blade.php js section
$('#result').on('click', function(){
var val = 3;
var _token = '';
$.ajax({
type:'POST',
url:'getProducts/'+val,
dataType:'JSON',
data:{_token:_token},
success: function(data){
console.log(data);
},
});
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire