Access Laravel API from a Laravel Nova custom tool
Asked Answered
M

0

7

I have created a new tool within Nova and I have to access my laravel api defined in /routes/api.php not the one in nova-components/component-name/routes/api.php

My code within the Vue component looks like this:

getCertificateTypes() {
    Nova.request().get('/api/certificate-type')
       .then(response => {
           // my code
       });
},

This returns a 401 Unauthorized

This is what I tried so far:

Added this code to my routes() function in the ServiceProvider of the tool created

Route::middleware(['nova', Authorize::class])
        ->prefix('laravel')
        ->group(__DIR__.'/../../../routes/api.php');

Now, if I call Nova.request().get('/laravel/api/certificate-type') I get a 404 not found.

What am I missing here?

Menton answered 10/1, 2020 at 12:38 Comment(3)
Is the routes method called in the service provider and is your serivce provider getting called? How does your routes/api.php look like?Endometrium
Did you find a solution to your question eventually? I am facing something similar at the moment.Akkadian
Unfortunately no, I just created a new controller in Nova which will get the data through the backend and call that controller.Menton

© 2022 - 2024 — McMap. All rights reserved.