https://twill.io logo
Join Discord
Powered by
# 📦packages
  • i

    ifox

    09/19/2022, 1:14 PM
    you need to declare this route above the module routes
  • o

    onepiece

    09/21/2022, 3:15 PM
    Hello I have a question. I am building a package and I have created a route in routes/api.php. But when I use it, I get a 404 error "vendor.js:229 POST http://127.0.0.1:8000/api/register/leads?locale=it 404 (Not Found)". My question is how can I use these routes in the project??
  • k

    kalle

    09/21/2022, 3:30 PM
    Can you please provide us with more info (routes and service provider which register routes).
  • o

    onepiece

    09/21/2022, 3:31 PM
    yep
  • o

    onepiece

    09/21/2022, 3:32 PM
    Inside the package at routes/api.php I have:
  • o

    onepiece

    09/21/2022, 3:33 PM
    in the component I am making an axios call
  • k

    kalle

    09/21/2022, 3:34 PM
    You dont have an group prefix here if you want to use it under
    /api/...
  • k

    kalle

    09/21/2022, 3:34 PM
    Copy code
    php
    Route::group(['prefix' => 'api'], function() {
      // Register your routes here
    }
  • o

    onepiece

    09/21/2022, 3:35 PM
    and i get this error
  • k

    kalle

    09/21/2022, 3:36 PM
    But you say, I quote "But when I use it, I get a 404 error "vendor.js:229 POST http://127.0.0.1:8000/api/register/leads?locale=it 404 "
  • k

    kalle

    09/21/2022, 3:36 PM
    This route differs from one from screenshot
  • o

    onepiece

    09/21/2022, 3:37 PM
    here in axios.post
  • k

    kalle

    09/21/2022, 3:40 PM
    Ok I understand you but still if
    api
    is just a prefix (not really API usage), you need to put correct route path so it gets registered
  • k

    kalle

    09/21/2022, 3:41 PM
    Currently for both routes you are missing prefix
    api
    (package api.php)
  • i

    ifox

    09/21/2022, 3:41 PM
    how is the api.php file registered in the package?
  • o

    onepiece

    09/21/2022, 3:43 PM
    in package provider??
  • i

    ifox

    09/21/2022, 3:43 PM
    yes can you share that part?
  • o

    onepiece

    09/21/2022, 3:45 PM
    To be honest, I have not registered api.php with the provider. How can I register it?
  • i

    ifox

    09/21/2022, 3:45 PM
    how do you expect api.php routes to be know to Laravel if you didn't register the file?
  • i

    ifox

    09/21/2022, 3:46 PM
    https://laravel.com/docs/9.x/packages#routes
  • i

    ifox

    09/21/2022, 3:46 PM
    your capsule routes are registered by Twill because Twill knows that a capsule can have a routes file
  • i

    ifox

    09/21/2022, 3:47 PM
    but the api.php file is custom to your package so it falls under standard Laravel package developement
  • o

    onepiece

    09/21/2022, 3:47 PM
    Sorry, but I thought differently. I didn't register admin.php either, but it recognized it
  • k

    kalle

    09/21/2022, 3:48 PM
    Glad its resolved, now I can go play some Halflife xd
  • i

    ifox

    09/21/2022, 3:49 PM
    because admin.php is inside a capsule and is the default routes file name Twill is looking for
  • o

    onepiece

    09/21/2022, 3:50 PM
    yep
  • k

    kalle

    09/21/2022, 3:52 PM
    But still I think he will have issue with route since its not grouped by
    api
    prefix. They will be registered normaly under
    /register/leads
    and
    updated/leads/{id}
    and not under
    api/register/leads
    /
    api/updated/leads/{id}
  • o

    onepiece

    09/22/2022, 7:04 AM
    Hello guys The problem is the same. And after I registered api routes with the provider, I got error 404 again
  • k

    kalle

    09/22/2022, 8:22 AM
    Are your sure your service provider gets discovered? Do you have registered it manualy or you use composer auto discovery feature? https://laravel.com/docs/9.x/packages#package-discovery
  • o

    onepiece

    09/22/2022, 8:25 AM
    It seems I solved it. I changed it from api.php to web.php. Now it works