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

Introduce Integration with barryvdh/laravel-ide-helper #77

Closed
mpyw opened this issue Apr 24, 2020 · 2 comments
Closed

Introduce Integration with barryvdh/laravel-ide-helper #77

mpyw opened this issue Apr 24, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@mpyw
Copy link
Contributor

mpyw commented Apr 24, 2020

I mentioned here:

It should be introduced also on README or Wiki.

<?php

namespace App\Console\Commands\IdeHelper;

use Barryvdh\LaravelIdeHelper\Console\ModelsCommand as BaseModelsCommand;
use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Relations\Relation;

class ModelsCommand extends BaseModelsCommand
{
    /**
     * @param  string   $relation
     * @param  Relation $relationObj
     * @return bool
     */
    protected function isRelationNullable(string $relation, Relation $relationObj): bool
    {
        $reflectionObj = new \ReflectionObject($relationObj);

        if (in_array($relation, ['hasOne', 'hasOneThrough', 'morphOne'], true) || !$reflectionObj->hasProperty('foreignKey')) {
            return parent::isRelationNullable($relation, $relationObj);
        }

        $fkProp = $reflectionObj->getProperty('foreignKey');
        $fkProp->setAccessible(true);

        return (bool)Arr::first(
            (array)$fkProp->getValue($relationObj),
            fn (string $value) => isset($this->nullableColumns[$value])
        );
    }
}
@topclaudy topclaudy added the enhancement New feature or request label Sep 15, 2020
@yurii-github
Copy link
Contributor

hello

it looks like you know this subject very closely. maybe you can make a PR for it?

afaik, this is something that cannot be done on compoships but only on laravel-ide-helper, right?

@calebdw
Copy link

calebdw commented Feb 8, 2024

Hello!

This issue has been fixed by the linked PR and can be closed

@mpyw mpyw closed this as completed Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants