Hi, i have created a project where i use Laravel as my backend and Vue.js as my front end but now that im testing my api in postman to see if i get any data i get this 403 This action is unauthorised, im still learning as i go but cant seem to get it working,
in postman i have this route http://localhost:8000/api/products as a get request
and in my .env i has this route APP_URL=http://localhost:8000
Im still learning to use api's and tried the whole day and googling what the cause might be but no luck,
If anyone can put me in the right direction i will really appreciate it
Here is my Products Controller
class ProductsController extends Controller
{
/**
* Display a listing of the resource.
*
* @param IndexProduct $request
* @return array|Factory|View
*/
public function index(IndexProduct $request)
{
// create and AdminListing instance for a specific model and
$data = AdminListing::create(Product::class)->processRequestAndGet(
// pass the request with params
$request,
// set columns to query
['brand', 'category', 'enabled', 'id', 'name', 'price', 'published_at', 'tax',],
// set columns to searchIn
['brand', 'category', 'description', 'id', 'name', 'price', 'tax']
);
if ($request->ajax()) {
if ($request->has('bulk')) {
return [
'bulkItems' => $data->pluck('id')
];
}
return ['data' => $data];
}
return view('admin.product.index', ['data' => $data]);
}
here is my product from request index page
class IndexProduct extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return Gate::allows('admin.product.index');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'orderBy' => 'in:brand,category,enabled,id,name,price,published_at,tax|nullable',
'orderDirection' => 'in:asc,desc|nullable',
'search' => 'string|nullable',
'page' => 'integer|nullable',
'per_page' => 'integer|nullable',
];
}
}
this is the api.php file
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::get('products', [ProductsController::class, 'index']);