Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command php artisan resource-file:create not working with --relations parameters #176

Open
SulaimanBello opened this issue Oct 14, 2021 · 0 comments

Comments

@SulaimanBello
Copy link

Environment:

  • Laravel-Code-Generator Version: v2.4.4
  • Laravel Version: v8.64.0

Description:

Following the documentation, this command php artisan resource-file:create could not work with --relations parameters.

Steps:

php artisan resource-file:append Post --fields="name:another" --relations="name:comments;type:hasMany;field:title;params:App\Models\Comment|post_id|id"

Running the cammand above would generate

ErrorException

Undefined offset: 1

The culprit seems to be the line below

  at ...\crestapps\laravel-code-generator\src\Models\ForeignRelationship.php:490
    486▕             if (!str_contains($part, ':')) {
    487▕                 continue;
    488▕             }
    489▕ 
  ➜ 490▕             list($key, $value) = Str::split([':', '='], $part);
    491▕ 
    492▕             if (($isParams = in_array($key, ['params', 'param'])) || str_contains($value, '|')) {
    493▕                 $value = explode('|', $value);
    494▕

A quick dirty fix was changing the line to:

list($key, $value) = Str::split(':', $part);

@SulaimanBello SulaimanBello changed the title Command php artisan resource-file:create not working with --relations parameters Command php artisan resource-file:create not working with --relations parameters Oct 14, 2021
@SulaimanBello SulaimanBello changed the title Command php artisan resource-file:create not working with --relations parameters Command php artisan resource-file:create not working with --relations parameters Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant