A RESTful API package for the Laravel and Lumen frameworks.

Related tags

API api
Overview

The Dingo API package is meant to provide you, the developer, with a set of tools to help you easily and quickly build your own API. While the goal of this package is to remain as flexible as possible it still won't cover all situations and solve all problems.

Build Status License Development Version Monthly Installs StyleCI

Features

This package provides tools for the following, and more:

  • Content Negotiation
  • Multiple Authentication Adapters
  • API Versioning
  • Rate Limiting
  • Response Transformers and Formatters
  • Error and Exception Handling
  • Internal Requests
  • API Blueprint Documentation

Documentation

Please refer to our extensive Wiki documentation for more information.

API Boilerplate

If you are looking to start a new project from scratch, consider using the Laravel API Boilerplate, which builds on top of the dingo-api package, and adds a lot of great features.

Support

For answers you may not find in the Wiki, avoid posting issues. Feel free to ask for support on the dedicated Slack room. Make sure to mention specialtactics so he is notified.

License

This package is licensed under the BSD 3-Clause license.

Comments
  • Lumen AND Laravel 5 Support

    Lumen AND Laravel 5 Support

    Hello all, I've recently pushed quite a number of changes to the develop branch that allows you to use this package in your Lumen and Laravel 5 apps.

    You can require it using 0.9.*@dev.

    Please note that if you're using Lumen you'll need to be using lumen-framework 5.0.*@dev for it to work correctly. These several routing changes that are yet to make it to a stable Lumen release.

    A few things to note...

    1. Much of the configuration can be done via environment variables now. You can still publish the config file in Laravel 5 and make changes that way. Lumen will require you to use the environment variables. For things that can't be set with environment variables there will be a method available on the underlying instance to change whatever it is you need.
    2. There is no internal dispatcher at this point in time. I was focusing on the core of the API for now to make that that's all sweet before moving on to the internal dispatcher.
    3. There is no route command at this point in time. It will be back.
    4. There is no URL generator at this point in time. it will be back.
    5. There's no facade at the moment. You will need to get an instance of the API router (app('api.router')) to register your routes.

    Here is a very quick sample of how it's now used. In your Lumen bootstrap/app.php file you'd register the Lumen provider.

    $app->register('Dingo\Api\Provider\LumenServiceProvider');
    
    // Get an instance of the API router so we can use it in the routes.php file
    $api = $app['api.router'];
    

    Now we can register our routes in the routes.php file.

    $api->version('v1', function ($api) {
        $api->resource('users', 'UserController');
    });
    

    All routing methods available in L5 are available in both L5 and Lumen. This includes standard routing with get, post, etc, as well as resource and controller routes.

    You can also setup group options much like in previous options (there is also an $api->group() method).

    $api->version('v1', ['namespace' => 'App', 'protected' => true], function ($api) {
        $api->resource('users', 'UserController');
    });
    

    Aside from that not a whole lot has changed but there are a few new things that I'll be talking about over time. For now, I'd love it if people could give it a whirl and let me know if they come across any issues. I'll iron things out as quick as I can.

    Cheers.


    Another thing to note is that a prefix or domain will be required now. You can set these via the environment variables API_PREFIX or API_DOMAIN respectively, or by publishing the config and making the appropriate changes.

    notice 
    opened by jasonlewis 145
  • Laravel 5 AND Lumen Support

    Laravel 5 AND Lumen Support

    Greetings API developer.

    Okay so I know quite a few people are jumping over to L5 to use all the latest and greatest stuff that it has to offer. That's fine. You can do that. But this package isn't L5 ready any more.

    This package will support the next version of Laravel. BUT, right now, I'm waiting for the dust to settle. There's a lot happening in there and I'll change one thing to fix something and before you know it another thing will change. So, for now, I'm going to iron out the remaining issues for 4.x and merge the develop branch over to master and start tagging 0.7.* releases.

    I'm hoping to get the package in a somewhat stable condition. My thoughts are to then create a branch specifically for L5 as there's a number of things that will need to be changed in order for it to be compatible.

    Any feedback, post it here.

    Cheers.


    Update 2014-05-17

    notice 
    opened by jasonlewis 137
  • Custom ExceptionHandler

    Custom ExceptionHandler

    Is it possible to overwrite the exception handler? If I would like to add custom syntax for the errors responses. Would be awesome if we could handle the entire exception handler outside of this package and use the default one that comes with the package out of the box.

    Dingo\Api\Routing\Router::__construct() must be an instance of Dingo\Api\Exception\Handler, instance of App\Exceptions\Handler given,
    
    opened by vinkla 56
  • Error 500 gives blank page with Lumen

    Error 500 gives blank page with Lumen

    Using the latest dev build to support Lumen, I'm getting blank error 500 pages. Am I missing any configuration parameter? Debug is set to true in both Dingo config and Lumen config.

    bug 
    opened by jonaholsson 39
  • Route Model Binding not working correctly with Laravel 5.3

    Route Model Binding not working correctly with Laravel 5.3

    I am having an issue with route model binding on my dingo (dev-master w/ L5.3 support) specific routes. On my Laravel web routes it works fine and returns the model with the correct data. It also works on Laravel 5.2.

    routes/api.php

    $api->get('users/{user}', ['as' => 'users.show', 'uses' => 'UserController@show']);
    

    UserController.php

    public function show(User $user)
    {
        dd($user);
    
        return $this->response->item($user, new UserTransformer);
    }
    

    The $user object is empty. I have tried with another controller too with the same results.

    I can only get it to work by using first(), which defeats the purpose of model binding.

    public function show(User $user)
    {
        $data = $user->first();
    
        return $this->response->item($data, new UserTransformer);
    }
    
    opened by dclawson 32
  • [L5] Request validation breaks router

    [L5] Request validation breaks router

    If I make input validation on a request using a request class like so

    <?php namespace App\Http\Requests;
    
    use App\Http\Requests\Request;
    
    class LoginRequest extends Request {
    
        /**
         * Determine if the user is authorized to make this request.
         *
         * @return bool
         */
        public function authorize()
        {
            return true;
        }
    
        /**
         * Get the validation rules that apply to the request.
         *
         * @return array
         */
        public function rules()
        {
            return [
                'email'    => 'required|email' ,
                'password' => 'required'
            ];
        }
    
    }
    

    it breaks the router on invalid input. The request class will issue a RedirectResponse and the Dingo router is expecting a normal Response resulting in the following exception being thrown.

    Argument 1 passed to Dingo\\Api\\Http\\Response::makeFromExisting() must be an instance of Illuminate\\Http\\Response, instance of Illuminate\\Http\\RedirectResponse given, called in \/home\/vagrant\/code\/traede-l5\/vendor\/dingo\/api\/src\/Routing\/Router.php on line 551 and defined
    

    I don't know if changing the type hinting to Symfony\Component\HttpFoundation\Response and dropping the getOriginalContent for a getContent is a valid solution. I tried it out and it seemed to work, however I did not thoroughly test it.

    Dingo\Api\Http\Response

    public static function makeFromExisting(\Symfony\Component\HttpFoundation\Response $old)
        {
            $new = static::create($old->getContent(), $old->getStatusCode());
    
            $new->headers = $old->headers;
    
            return $new;
        }
    
    opened by esbenp 32
  • Internal routing bug: doesn't work with middleware

    Internal routing bug: doesn't work with middleware

    Any internal request in conjunction with a route that contains middleware, like this:

    $api->version('v1', ['middleware' => 'test'], function ($api) {
    
    });
    

    Results in a:

    [ReflectionException]      
      Class test does not exist 
    

    Despite it being define properly inside Kernel.php:

     protected $routeMiddleware = [
            'test' => \App\Http\Middleware\Test::class,
            'auth' => \App\Http\Middleware\Authenticate::class,
            'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
            'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
            'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        ];
    

    I've created a test case to illustrate the bug here https://github.com/assembledadam/laravel

    Just run php artisan testcase in the root folder, and to view the middleware working visit localhost/index.php/test/blahblah

    Stack trace (from my application, not the test case!):

    n Error Occured:
    Class oauth does not exist
    File: /usr/www/app/vendor/laravel/framework/src/Illuminate/Container/Container.php
    Line: 738
    #0 /usr/www/app/vendor/laravel/framework/src/Illuminate/Container/Container.php(738): ReflectionClass->__construct('oauth')
    #1 /usr/www/app/vendor/laravel/framework/src/Illuminate/Container/Container.php(633): Illuminate\Container\Container->build('oauth', Array)
    #2 /usr/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('oauth', Array)
    #3 /usr/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(123): Illuminate\Foundation\Application->make('oauth')
    #4 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Dingo\Api\Http\InternalRequest))
    #5 /usr/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Dingo\Api\Http\InternalRequest))
    #6 /usr/www/app/vendor/dingo/api/src/Http/Middleware/PrepareController.php(45): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Dingo\Api\Http\InternalRequest))
    #7 [internal function]: Dingo\Api\Http\Middleware\PrepareController->handle(Object(Dingo\Api\Http\InternalRequest), Object(Closure))
    #8 /usr/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
    #9 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Dingo\Api\Http\InternalRequest))
    #10 /usr/www/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Dingo\Api\Http\InternalRequest))
    #11 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Dingo\Api\Http\InternalRequest))
    #12 /usr/www/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Dingo\Api\Http\InternalRequest))
    #13 /usr/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(726): Illuminate\Pipeline\Pipeline->then(Object(Closure))
    #14 /usr/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(699): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Dingo\Api\Http\InternalRequest))
    #15 /usr/www/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(675): Illuminate\Routing\Router->dispatchToRoute(Object(Dingo\Api\Http\InternalRequest))
    #16 /usr/www/app/vendor/dingo/api/src/Routing/Adapter/Laravel.php(80): Illuminate\Routing\Router->dispatch(Object(Dingo\Api\Http\InternalRequest))
    #17 /usr/www/app/vendor/dingo/api/src/Routing/Router.php(574): Dingo\Api\Routing\Adapter\Laravel->dispatch(Object(Dingo\Api\Http\InternalRequest), 'v1')
    #18 /usr/www/app/vendor/dingo/api/src/Dispatcher.php(540): Dingo\Api\Routing\Router->dispatch(Object(Dingo\Api\Http\InternalRequest))
    #19 /usr/www/app/vendor/dingo/api/src/Dispatcher.php(445): Dingo\Api\Dispatcher->dispatch(Object(Dingo\Api\Http\InternalRequest))
    #20 /usr/www/app/vendor/dingo/api/src/Dispatcher.php(372): Dingo\Api\Dispatcher->queueRequest('post', 'users', Array, '{"old_id":"301"...')
    #21 /usr/www/app/vendor/candybanana/creo-migration/src/ETL/Scripts/User.php(240): Dingo\Api\Dispatcher->post('users', Array, '{"old_id":"301"...')
    #22 /usr/www/app/vendor/candybanana/creo-migration/src/ETL/Scripts/AbstractMigration.php(178): Candybanana\CreoMigration\ETL\Scripts\User->insert(Array)
    #23 /usr/www/app/vendor/candybanana/creo-migration/src/ETL/Scripts/User.php(68): Candybanana\CreoMigration\ETL\Scripts\AbstractMigration->run(NULL, '114947')
    #24 /usr/www/app/vendor/candybanana/creo-migration/src/ETL/ETL.php(348): Candybanana\CreoMigration\ETL\Scripts\User->__construct(Object(Candybanana\CreoMigration\ETL\ETL), '0adf04fce0090b6...')
    #25 /usr/www/app/vendor/candybanana/creo-migration/src/ETL/ETL.php(262): Candybanana\CreoMigration\ETL\ETL->runEntityScripts(Array)
    #26 /usr/www/app/vendor/candybanana/creo-migration/src/ETL/ETL.php(91): Candybanana\CreoMigration\ETL\ETL->run()
    #27 /usr/www/app/vendor/candybanana/creo-migration/src/Console/Command/Migrate.php(87): Candybanana\CreoMigration\ETL\ETL->__construct(Array, Object(Candybanana\CreoMigration\Console\Command\Migrate), Object(PDO))
    #28 [internal function]: Candybanana\CreoMigration\Console\Command\Migrate->fire()
    #29 /usr/www/app/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
    #30 /usr/www/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
    #31 /usr/www/app/vendor/symfony/console/Command/Command.php(259): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #32 /usr/www/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #33 /usr/www/app/vendor/symfony/console/Application.php(844): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #34 /usr/www/app/vendor/symfony/console/Application.php(192): Symfony\Component\Console\Application->doRunCommand(Object(Candybanana\CreoMigration\Console\Command\Migrate), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #35 /usr/www/app/vendor/symfony/console/Application.php(123): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #36 /usr/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #37 /usr/www/app/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #38 {main}
    
    opened by assembledadam 31
  • Call to undefined method Illuminate\Routing\Router::api()

    Call to undefined method Illuminate\Routing\Router::api()

    Today I wanted to try and make my first API using laravel and this package.

    I have trouble configuring it to work properly.

    First I've changed the version to the latest one on dev-master by using composer to walk around the issue #121 (There is no API route collection...)

    I added the service provider.

    Then I have published the configuration. I also added aliases like so:

    'aliases' => array(
    
        //API
        'API'             => 'Dingo\Api\Facades\API',
        //Controller class from Laravel
        //'Controller'    => 'Illuminate\Routing\Controller',
        //Controller from dingo/api
        'Controller'      => 'Dingo\Api\Routing\Controller',
    
    ),
    

    After loading up my app, I encountered the following error:

    PHP Fatal error:  Call to undefined method Illuminate\Routing\Router::api() in /home/marcin/phpStormProjects/DziennikLoginWebNew/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 211
    

    It seems laravel tries to use it's own routing class instead of the one provided by the package. How do I configure it to resolve correctly?

    opened by marcinlawnik 29
  • Internal request doesn't send data

    Internal request doesn't send data

    I am sending POST data (username and password) to /proxy where i add some more data to array and make Internal request to /oauth/access_token with new array.

    $request = app('request')->only('username', 'password');
    
    $credentials = [
        'grant_type'    => 'password',
        'username'      => $request['username'],
        'password'      => $request['password'],
        'client_id'     => env('OAUTH_CLIENT_ID'),
        'client_secret' => env('OAUTH_CLIENT_SECRET')
    ];
    
    try{
        $response = $dispatcher->post('oauth/access_token', $credentials);
    }catch (InternalHttpException $e)
    {
        return response()->json($e->getResponse()->original);
    }
    

    But the problem is that data /oauth/access_token gets is only username and password from request to /proxy, and not new array.

      +request: ParameterBag {#130
        #parameters: array:2 [
          "username" => "Username"
          "password" => "Password"
        ]
    

    What did I do wrong?

    opened by mentos1386 28
  • Dingo\Api\Dispatcher not respecting route

    Dingo\Api\Dispatcher not respecting route

    The App Controller

    <?php
    
    namespace App\Http\Controllers;
    
    class CustomersController extends Controller
    {
        /**
         * @var Dingo\Api\Dispatcher
         */
        protected $dispatcher;
    
        /**
         * Initialize
         *
         * @param Dingo\Api\Dispatcher $dispatcher
         */
        public function __construct(Dispatcher $dispatcher)
        {
            $this->middleware('auth');
    
            $this->dispatcher = $dispatcher;
        }
    
        /**
         * Display a listing of the resource.
         *
         * @return \Illuminate\Http\Response
         */
        public function index()
        {
            $customers = $this->dispatcher->version('v0')->get('customers');
            // $customers = Customer::all();
    
            return view('customers.index', compact('customers'));
        }
    ...
    }
    

    The API Controller

    <?php
    
    namespace App\Http\Controllers\Api\V0;
    
    class CustomersController extends Controller
    {
        /**
         * Initialize
         */
        public function __construct()
        {
            $this->middleware('auth');
        }
    
        /**
         * Display a listing of the resource.
         *
         * @return \Illuminate\Http\Response
         */
        public function index()
        {
            return Customer::all();
        }
    ...
    }
    

    The Test

    ...
        /** @test */
        public function it_creates_a_new_customer()
        {
            $store = factory(Store::class)->create();
    
            $dummy = factory(Customer::class)->make([
                'store_id' => $store->id,
            ]);
    
            $this->visit(route('customers.create'))
                 ->see('Adauga un client nou.')
                 ->select($store->id, 'store_id')
                 ->type($dummy->first_name, 'first_name')
                 ->type($dummy->last_name, 'last_name')
                 ->type($dummy->email, 'email')
                 ->type($dummy->phone, 'phone')
                 ->press('Add')
                 ->seePageIs(route('customers.index')) // **This is not working anymore**
                 ->see($dummy->name);
    
            $data = array_only($dummy->toArray(), [
                'first_name', 'last_name',
                'phone', 'email',
            ]);
    
            $this->seeInDatabase('customers', $data);
    
            $customer = Customer::first();
    
            $this->assertEquals("{$dummy->first_name} {$dummy->last_name}", $customer->name);
            $this->assertNotNull($customer->token);
        }
    ...
    

    The $this->seePageIs(route('customers.index')) is not working anymore; it records as being still on the create page.

    1) CustomerTest::it_creates_a_new_customer
    Did not land on expected page [http://localhost/customers].
    
    Failed asserting that two strings are equal.
    --- Expected
    +++ Actual
    @@ @@
    -'http://localhost/customers'
    +'http://localhost/customers/create'
    

    This all works well if I comment out this code $customers = $this->dispatcher->version('v0')->get('customers'); from the Controller and leave the Eloquent object in.

    It works well if I view the customers.index route in the browser. Even adding a new customer works well in the browser.

    bug 
    opened by arthurkirkosa 27
  • API::route()

    API::route()

    Hey Jason, any chance you wanted to build in support for the route() call vs clunky url patterns? :) I think it would be fantastic to do that, so in your internal API requests, they could be so clean.

    opened by ryanhungate 26
  • Getting this error

    Getting this error "Unable to resolve transformer binding"

    | Q | A | ----------------- | --- | Bug? | yes | New Feature? | no | Framework | Laravel | Framework version | ^6.0 | Package version | ^2.0 | PHP version | 7.4

    Actual Behaviour

    {"message":"Unable to resolve transformer binding.","status_code":500}

    opened by ratneshkumar41 0
  • $appends variables function got additional 3 times execution

    $appends variables function got additional 3 times execution

    | Q | A | ----------------- | --- | Bug? |yes | New Feature? | no | Framework | Laravel | Framework version | 5.5.y & ^8.0 | Package version | v2.0.0-alpha1 & ^3.0 | PHP version |7.x.y

    Actual Behaviour

    get{$Variable}Attribute of $appends variable on the eloquent model got 3 times additional execution when the response returned using single item response function (return $this->response->item)

    Steps to Reproduce

    • add $appends variable on the model
    • write a log on the get{$Variable}Attribute function and the log will written 3 times for each item
    opened by mahadi-siregar 0
  • When declaring multiple resource routes, all but the first fail to pass the parameter correctly.

    When declaring multiple resource routes, all but the first fail to pass the parameter correctly.

    | Q | A | ----------------- | --- | Bug? | unsure | New Feature? | no | Framework | Lumen | Framework version | 8.3.1 | Package version | 3.0.7 | PHP version | 7.4

    Actual Behaviour

    When setting up multiple api resource routes, only the first resource is working as expected, the others return an error similar to Unable to resolve dependency [Parameter #0 [ <required> $user_id ]] in class App\\Http\\Controllers\\UserController

    Here's my web.php file:

    <?php
    
    /** @var \Laravel\Lumen\Routing\Router $router */
    
    use App\Http\Controllers\ApiAuthController;
    use App\Http\Controllers\IndexController;
    use App\Http\Controllers\CompanyController;
    use App\Http\Controllers\RoleController;
    use App\Http\Controllers\UserAuthController;
    use App\Http\Controllers\UserController;
    
    $api = app('Dingo\Api\Routing\Router');
    
    $api->version('v1', function ($api) {
    
        $api->group(['middleware' => ['log']], function ($api) {
            $api->post('/login', [ApiAuthController::class, 'postAuthenticate']);
            $api->post('/users/login', [UserAuthController::class, 'postAuthenticate']);
        });
    
        $api->group(['middleware' => ['auth', 'log']], function ($api) {
    
            //Root Route. This prevents any leaky details if someone tries to hit the API in the browser
            $api->get('/', [IndexController::class, 'getIndex']);
    
            //Company Routes
            $api->resource('companies', CompanyController::class, [
                'parameters' => ['companies' => 'company_id'],
            ]);
    
            //Role Routes
            $api->resource('roles', RoleController::class, [
                'parameters' => ['roles' => 'role_id'],
            ]);
    
            //User Auth Routes
            $api->post('/users/logout', [UserAuthController::class, 'postLogout']);
            $api->post('/users/refresh', [UserAuthController::class, 'postRefresh']);
    
            //User Routes
            $api->resource('users', UserController::class, [
                'parameters' => ['users' => 'user_id'],
            ]);
        });
    });
    

    If I send a GET request to /companies/5837991a-9f8d-47d7-9453-13e1b67bae35 I get a 200 OK response and the request data. However if I send a GET request to /roles/0553a087-457a-4124-8669-ca29f4c06c64 or users/46e8b3a5-085d-4f4a-bf30-411159591b56 I get the 500 Internal Server Error posted above (substitute Controller/Key details). If however, I move the API Resource statements around, for example, putting the Role Routes before the Company Routes, the request to /roles/0553a087-457a-4124-8669-ca29f4c06c64 will work, but the request to /companies/5837991a-9f8d-47d7-9453-13e1b67bae35 will fail.

    The show method from CompanyController.php

        public function show($company_id)
        {
            $company = Company::findOrFail($company_id);
            return $this->response->item($company, new CompanyTransformer);
        }
    

    The show method from RoleController.php

        public function show($role_id)
        {
            $role = Role::findOrFail($role_id);
            return $this->response->item($role, new RoleTransformer);
        }
    

    Stack Trace of Error:

    {
        "message": "Unable to resolve dependency [Parameter #0 [ <required> $user_id ]] in class App\\Http\\Controllers\\UserController",
        "status_code": 500,
        "debug": {
            "line": 182,
            "file": "/mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/container/BoundMethod.php",
            "class": "Illuminate\\Contracts\\Container\\BindingResolutionException",
            "trace": [
                "#0 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/container/BoundMethod.php(124): Illuminate\\Container\\BoundMethod::addDependencyForCallParameter()",
                "#1 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/container/BoundMethod.php(36): Illuminate\\Container\\BoundMethod::getMethodDependencies()",
                "#2 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()",
                "#3 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()",
                "#4 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()",
                "#5 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/container/Container.php(653): Illuminate\\Container\\BoundMethod::call()",
                "#6 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(389): Illuminate\\Container\\Container->call()",
                "#7 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(355): Laravel\\Lumen\\Application->callControllerCallable()",
                "#8 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(329): Laravel\\Lumen\\Application->callLumenController()",
                "#9 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(282): Laravel\\Lumen\\Application->callControllerAction()",
                "#10 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(262): Laravel\\Lumen\\Application->callActionOnArrayBasedRoute()",
                "#11 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(48): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}()",
                "#12 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/app/Http/Middleware/BeforeRequestLogs.php(56): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}()",
                "#13 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/pipeline/Pipeline.php(167): App\\Http\\Middleware\\BeforeRequestLogs->handle()",
                "#14 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()",
                "#15 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/app/Http/Middleware/Authenticate.php(42): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}()",
                "#16 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/pipeline/Pipeline.php(167): App\\Http\\Middleware\\Authenticate->handle()",
                "#17 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()",
                "#18 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/dingo/api/src/Http/Middleware/PrepareController.php(45): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}()",
                "#19 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/pipeline/Pipeline.php(167): Dingo\\Api\\Http\\Middleware\\PrepareController->handle()",
                "#20 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()",
                "#21 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/pipeline/Pipeline.php(103): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}()",
                "#22 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(426): Illuminate\\Pipeline\\Pipeline->then()",
                "#23 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(263): Laravel\\Lumen\\Application->sendThroughPipeline()",
                "#24 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(237): Laravel\\Lumen\\Application->handleFoundRoute()",
                "#25 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(173): Laravel\\Lumen\\Application->handleDispatcherResponse()",
                "#26 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(429): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}()",
                "#27 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(175): Laravel\\Lumen\\Application->sendThroughPipeline()",
                "#28 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/dingo/api/src/Routing/Adapter/Lumen.php(116): Laravel\\Lumen\\Application->dispatch()",
                "#29 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/dingo/api/src/Routing/Router.php(518): Dingo\\Api\\Routing\\Adapter\\Lumen->dispatch()",
                "#30 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/dingo/api/src/Http/Middleware/Request.php(126): Dingo\\Api\\Routing\\Router->dispatch()",
                "#31 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/pipeline/Pipeline.php(128): Dingo\\Api\\Http\\Middleware\\Request->Dingo\\Api\\Http\\Middleware\\{closure}()",
                "#32 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()",
                "#33 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/dingo/api/src/Http/Middleware/Request.php(127): Illuminate\\Pipeline\\Pipeline->then()",
                "#34 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/dingo/api/src/Http/Middleware/Request.php(103): Dingo\\Api\\Http\\Middleware\\Request->sendRequestThroughRouter()",
                "#35 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/pipeline/Pipeline.php(167): Dingo\\Api\\Http\\Middleware\\Request->handle()",
                "#36 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()",
                "#37 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/illuminate/pipeline/Pipeline.php(103): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}()",
                "#38 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(426): Illuminate\\Pipeline\\Pipeline->then()",
                "#39 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(175): Laravel\\Lumen\\Application->sendThroughPipeline()",
                "#40 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(112): Laravel\\Lumen\\Application->dispatch()",
                "#41 /mnt/c/www/api.myapi.io.local/data/api-myapi-io/public/index.php(28): Laravel\\Lumen\\Application->run()",
                "#42 {main}"
            ]
        }
    

    While trying to track down the issue, what I'm finding is in the BoundMethod.php file, it's looking for $paramName (user_id) in the $parameters array. However, the parameters array is indexing the value as user. From what I'm finding in the Naming Resource Route Parameters it looks like this is working for the first resource, but subsequent resources are using the default singularized version.

    array(1) {
        [
            "user"
        ]=>
      string(36) "46e8b3a5-085d-4f4a-bf30-411159591b56"
    }
    

    Expected Behaviour

    I would expect that the various resource routes would all assign the parameter variables and load the controller as expected.

    Steps to Reproduce

    I believe all of the various code snippets and other items needed are all spelled out in the section above.

    Possible Solutions

    It looks like I could remove the specified parameters and use the singular variable in the controllers, but I like passing the variable like user_id as opposed to $user and reserve the singular for the model.

    opened by drahija-gli 0
  • Missing required parameter for [Route: users.show] [URI: api/users/{id}] [Missing parameter: id]

    Missing required parameter for [Route: users.show] [URI: api/users/{id}] [Missing parameter: id]

    | Defining routes with parameter | --- | Bug? | no | New Feature? | no | Framework | Laravel | Framework version | 8.54 | Package version | 3.0.0 | PHP version | 7.4.22

    Actual Behaviour

    Hey everyone, I am new to Dingo API and following documentation but I am struggling with creating routes with parameters. When I send a request to localhost/users it works as expected and response me all users in database. But when I try to send a request to show a specific user via id parameter, it returns 500 error with following message, also if I run a php artisan command it gives me the same error: Illuminate\Routing\Exceptions\UrlGenerationException Missing required parameter for [Route: users.show] [URI: api/users/{id}] [Missing parameter: id].

    Steps to Reproduce

    api routes:

    $api = app('Dingo\Api\Routing\Router');
    
    $api->version('v1', function ($api) {
        $api->get('users/{id}', ['as' => 'users.show', 'uses' => 'App\Http\Controllers\Api\V1\UserController@show']);
        $api->get('users', ['as' => 'users.index', 'uses' => 'App\Http\Controllers\Api\V1\UserController@index']);
    
        app('Dingo\Api\Routing\UrlGenerator')->version('v1')->route('users.show');
        app('Dingo\Api\Routing\UrlGenerator')->version('v1')->route('users.index');
    });
    

    User Controller

    class UserController extends Controller
    {
        public function index()
        {
            return User::all();
        }
    
        public function show($id)
        {
            return User::where("id",$id)->first();
        }
    }
    

    How can I fix this? Thanks in advance.

    opened by hsariaslan 0
Releases(v3.0.8)
Owner
null
PHP REST API without using any frameworks. Contains all CRUD operations.

PHP REST API without any framework and CRUD operations ?? Hi there, this is a simple REST API built in PHP without using any frameworks. This is built

Hanoak 10 Sep 5, 2022
Best resources restful api for developers (with JSON:API standar specification design)

List API Best resources restful api for developers (with JSON:API standar specification design). API Resource Endpoint Name Resource Description Al Qu

Noval 2 Jan 18, 2022
A simple way of authenticating your RESTful APIs with API keys using Laravel

ApiGuard This package is no longer maintained This package is no longer maintained as Laravel already has a similar feature built-in since Laravel 5.8

Chris Bautista 691 Nov 29, 2022
A simple example of how to create a RESTful API in Laravel Framework 8.36.1.

FirstLaravel A simple example of how to create a RESTful API in Laravel Framework 8.36.1. I used Database sqlite because I wanted to deploy this proje

Max Base 4 Apr 16, 2021
My first laravel restful api project

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Amirhosein Mohammadian 2 Oct 13, 2021
Fully documented & tested Laravel 9 RESTful books API scraped from Gramedia.

Laravel Books API Introduction This app provides a list of books in a RESTful API. Source of data obtained from Gramedia by using the web scraping tec

Yusuf T. 44 Dec 23, 2022
Best resources restful api for developers

Best resources restful api for developers (with JSON:API standar specification design).

Noval 2 Jan 18, 2022
A RESTful and extendable Backend as a Service that provides instant backend to develop sites and apps faster, with dead-simple integration for JavaScript, iOS, Android and more.

Welcome to hook ![Gitter](https://badges.gitter.im/Join Chat.svg) hook is a RESTful, extendable Backend as a Service that provides instant backend to

doubleleft 762 Dec 30, 2022
API for Symbiota using the Lumen PHP PHP Micro-Framework By Laravel

symbiota-api API for Symbiota using the Lumen PHP PHP Micro-Framework By Laravel Laravel Lumen Official Documentation Documentation for the Lumen fram

Biodiversity Knowledge Integration Center 2 Jan 3, 2022
PHP SDK for Checkout RESTful APIs

REST API SDK for PHP V2 To consolidate support across various channels, we have currently turned off the feature of GitHub issues. Please visit https:

PayPal 400 Nov 29, 2022
PHP SDK for PayPal RESTful APIs

Deprecation Notice: This SDK is deprecated. You can continue to use it, but no new features or support requests will be accepted. For alternatives, pl

PayPal 2.1k Jan 5, 2023
An easy to use Fractal wrapper built for Laravel and Lumen applications

An easy to use Fractal wrapper built for Laravel and Lumen applications The package provides a nice and easy wrapper around Fractal for use in your La

Spatie 1.8k Dec 30, 2022
Generates OpenApi specification for Laravel, Lumen or Dingo using a configuration array and cebe/php-openapi

OpenApi Generator for Laravel, Lumen and Dingo. About The openapi-gen package provides a convenient way to create OpenApi specifications for Laravel,

Jean Dormehl 5 Jan 25, 2022
Fully unit tested Facebook SDK v5 integration for Laravel & Lumen

Laravel Facebook SDK A fully unit-tested package for easily integrating the Facebook SDK v5 into Laravel and Lumen 5.0, 5.1, 5.2, & 5.3. This is packa

Sammy Kaye Powers 697 Nov 6, 2022
Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using laravel best practices.

Laravel API tool kit and best API practices Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using lar

Ahmed Esa 106 Nov 22, 2022
A Laravel Fractal package for building API responses, giving you the power of Fractal with Laravel's elegancy.

Laravel Responder is a package for building API responses, integrating Fractal into Laravel and Lumen. It can transform your data using transformers,

Alexander Tømmerås 776 Dec 25, 2022
This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.

PHP API TO-DO-LIST v.2.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science cours

Edson M. de Souza 6 Oct 13, 2022
JSON API (jsonapi.org) package for Laravel applications.

cloudcreativity/laravel-json-api Status This package has now been rewritten, substantially improved and released as the laravel-json-api/laravel packa

Cloud Creativity 753 Dec 28, 2022
This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses and the like.

Simple PHP API v.1.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses a

Edson M. de Souza 14 Nov 18, 2021