Skip to content

Conversation

ghostwriter
Copy link
Contributor

draft.yaml:

models:
  Salesman:
    name: string
    relationships:
      hasOne: User:Lead
      hasMany: class_name:method_name
      belongsTo: class_name:method_name

Output:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Salesman extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
    ];


    public function lead()
    {
        return $this->hasOne(\App\User::class);
    }

    public function methodNames()
    {
        return $this->hasMany(\App\ClassName::class);
    }

    public function methodName()
    {
        return $this->belongsTo(\App\ClassName::class);
    }
}

@jasonmccreary jasonmccreary merged commit 125d242 into laravel-shift:master Aug 29, 2020
@ghostwriter ghostwriter deleted the test/alias-relationships branch August 29, 2020 19:09
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

Successfully merging this pull request may close these issues.

FR: ability to alias relationships
2 participants