While creating a model columns with custom column name (doesn't follow laravel convention). It doesn't add column name to relation.
So let's say i have following Yaml
Sample 1
models:
Post:
id
content: text nullable
created_by_id: id nullable bigInteger unsigned foreign:users.id
timestamps
softDeletes
Expected Behavior:
While generating Model relations It can automatically add created_by_id as second argument. And
public function createdBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(\App\Models\User::class,"created_by_id");
}
Sample 2
models:
Post:
id
content: text nullable
created_by_id: id nullable bigInteger unsigned foreign:users.user_id
timestamps
softDeletes
Expected Behavior:
While generating Model relations It can automatically add created_by_id and as second argument as user_id
public function createdBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(\App\Models\User::class,"created_by_id","user_id");
}
Synopsis:
While creating a model columns with custom column name
(doesn't follow laravel convention)
. It doesn't add column name to relation.So let's say i have following Yaml
Sample 1
Expected Behavior:
While generating Model relations It can automatically add
created_by_id
as second argument. AndSample 2
Expected Behavior:
While generating Model relations It can automatically add
created_by_id
and as second argument asuser_id