每当我尝试从我的api.php文件中分配路由时,我得到一个401: Unauthenticated-Error.
这是路线:
Route::group(['prefix' => 'v1', 'middleware' => 'auth:api'], function () {
Route::post('admin/product-image-sort', 'ApiController@SaveProductImageSort')->name('api.save-product-image-sort');
});
Run Code Online (Sandbox Code Playgroud)
我使用Jquery Ajax调用它:
<script>
$('#sortable-image-container').sortable({
items: '> .row > *',
update: function (event, ui) {
var data = $(this).sortable('serialize');
console.log(data);
$.ajax({
data: data,
type: 'POST',
url: "{{ route('api.save-product-image-sort') }}",
success: function (data) {
if(data == "success"){
$.notify({
icon: 'pe-7s-close-circle',
message: "Sucessfully saved the Image Sorting"
},{
type: 'success',
timer: 500
});
}
}
});
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
因此,在排除'middleware' => 'auth:api'部件时这可以完美无缺,但我不想仅仅允许在没有任何形式的身份验证的情况下访问我的内部api. …