Skip to content
This repository was archived by the owner on Feb 2, 2022. It is now read-only.
This repository was archived by the owner on Feb 2, 2022. It is now read-only.

Make some models macroable #107

@larsjanssen6

Description

@larsjanssen6

Hi,

Would it be an idea to make some models macroable.

For example I need to add an address to the order model. If the order
model was macroable I could add the relation like this:

Boot method in serviceprovider:

Illuminate\Database\Eloquent\Builder::macro(‘address’, function() {
    $model = $this->getModel();
    
    if($model instanceof App\Address) {
         return $model->belongsToMany(App\Address::class);
    }
    unset(static::$macros['address']);
    return $model->address();
 });

Would you accept a PR for this or is there a better way?

Thanks!

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