Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.
This repository was archived by the owner on Jun 11, 2026. It is now read-only.

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

@SulaimanBello

Description

@SulaimanBello

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions