Lomkit / laravel-rest-api

Generate Api in seconds
https://laravel-rest-api.lomkit.com/
MIT License
298 stars 18 forks source link

Generated resource: incorrect class/namespace #53

Closed timyourivh closed 9 months ago

timyourivh commented 9 months ago

Laravel Rest Api Version

1.1

Laravel Version

10.10

PHP Version

8.2

Database Driver & Version

MySQL 8.1.0 on Windows 10 Pro (x64)

Description

When generating a resource using the php artisan rest:resource {name} command it will generate a resource class but generates the actions and instructions methods with an incorrectly namespaced class. This class is not used/imported into the resource class by default, which results in an Exception and intelisense errors:

image

What it should look like:

image

To fix this I can see 2 possible solutions:

  1. Fix the classes on the actions and instructions methods to include the full class path.
  2. Import the class into the file (use \Lomkit\Rest\Http\Requests\RestRequest;) and remove the full path from the other methods.

I noticed you prefer to include the complete path so I may create a PR applying solution 1 if allowed.

Steps To Reproduce

  1. Install lomkit/laravel-rest-api^1.1
  2. Run command php artisan rest:resource TestResource
  3. Inspect the generated file, should be located at {projectroot}/app/Rest/Resources/TestResource.php
  4. Scroll down to the actions and instructions methods and see the incorrect result.
GautierDele commented 9 months ago

Hello @timyourivh,

Thanks for your feedback ! I'd prefer adding this with full class path, that's what i'm used to see in most cases. If you find time, feel free to submit a PR, i also might be able to do this this week-end :)