dingo / api

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

Call to a member function toArray() on null #1658

Closed lyongdee closed 5 years ago

lyongdee commented 5 years ago
Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 5.7.19
Package version 2.2.3
PHP version 7.1.19

Actual Behaviour

8A035BF4-D74A-4f8a-B111-7F07681ED4FC

As shown in the picture, when running : $ php artisan api:routes That's will return : Symfony\Component\Debug\Exception\FatalThrowableError : Call to a member function toArray() on null

But the code above I wrote works fine, how to solve it.

Expected Behaviour

show api:routes

Steps to Reproduce

List all the steps needed to reproduce the issue you're having. Make sure to include code (affected models, configurations), any screenshots and/or other resources that may help us understand what's going on.

Possible Solutions

If you have any ideas on how to solve the issue, add them here, otherwise you can omit this part.

sudkumar commented 5 years ago

@lyongdee Can you run php artisan successfully ? Or it is also throwing the same error ?

lyongdee commented 5 years ago

@sudkumar php artisan is ok, and other commands is ok

specialtactics commented 5 years ago

The problem is definitely in your code - It's triggered from your controller.

Even though it may work fine through HTTP - this is irrelevant, because you are not considering what affect your code has when the controller is bootstrapped from CONSOLE for the purposes of that command. This may not matter at all, but if you want to run that command, you need to take this into consideration.