dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.32k stars 1.25k forks source link

php artisan api:routes wrong Action #663

Closed oleynikd closed 9 years ago

oleynikd commented 9 years ago

Hi,

First of all thank you for such a great tool!

Here's my route:

$api = app('Dingo\Api\Routing\Router');
$api->version('v3', function ($api) {
    $api->post('auth/register', 'App\Http\Controllers\API\AuthController@postRegister');
});

And here's the result of php artisan api:routes: screenshot 2015-09-24 19 34 57

Why is Action = Closure?

I'm using:

Thanks.

jlien-calwater commented 9 years ago

@oleynikd could be result of your controller?

I just tested this in my route.

image

Try referencing it to a plain vanilla controller.

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

class AuthController extends Controller
{

    public function postRegister(Request $request)
    {
        return $request->all();
    }

}
oleynikd commented 9 years ago

I tried plain vanilla controller - that did not helped.

oleynikd commented 9 years ago

I'm also using laravel/spark... Not sure if this changes something?

rossedman commented 9 years ago

I am having the same problem. If I change the controller to a class that does not exists it throws an error, but it does not register the method when set correctly.

jlien-calwater commented 9 years ago

@oleynikd not sure if it is supported at this time. Current support is Laravel 5.1+ or Lumen 5.1+ from what I understand. Best create a test case with plain vanilla?

rossedman commented 9 years ago

My problem seemed to be with subdomain vs domain. You can not set your subdomain equal to the domain. That is as far as I have got. Begs the question what if you want an API on its own domain?

oleynikd commented 9 years ago

I also have my API on separate subdomain using API_DOMAIN env variable, but removing it did not helped.

I tried new plain installation of laravel and dingo/api - result is the same!

Here's the simple repo to illustrate the issue: https://github.com/oleynikd/laravel-dingo-routes-test There are 3 commits to describe changes I made. If I do:

git clone https://github.com/oleynikd/laravel-dingo-routes-test.git
cd laravel-dingo-routes-test/
composer install
php artisan api:route

I get: screenshot 2015-09-28 23 27 35

Hope this will help.

P.S. If you skip this step:

php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"

after dingo\api installation you'll get:

[ErrorException]
Argument 2 passed to Dingo\Api\Exception\Handler::__construct() must be of the type array, null given, called in .../vendor/dingo/api/src/Provider/ApiServiceProvider.php on line 125 and defined

But on Wiki page this step is described as optional...

Thanks.

jasonlewis commented 9 years ago

Just pushed a fix.

As for the exception you're see @oleynikd, place the API service provider above the application ones. That way everything is being registered and booted before your application providers are registered and booted. Will mention this in documentation.

oleynikd commented 9 years ago

Thank you @jasonlewis