Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ protected function buildRelationships(Model $model)
}

$fqcn = Str::startsWith($fqcn, '\\') ? $fqcn : '\\' . $fqcn;
$fqcn = Str::is($fqcn, "\\{$model->fullyQualifiedNamespace()}\\{$class_name}") ? $class_name : $fqcn;

if ($type === 'morphTo') {
$relationship = sprintf('$this->%s()', $type);
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/models/alias-relationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ class Salesman extends Model

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

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

public function methodName()
{
return $this->belongsTo(\App\ClassName::class);
return $this->belongsTo(ClassName::class);
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/models/certificate-pascal-case-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ class Certificate extends Model

public function certificateType()
{
return $this->belongsTo(\App\CertificateType::class);
return $this->belongsTo(CertificateType::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class CertificateType extends Model

public function certificates()
{
return $this->hasMany(\App\Certificate::class);
return $this->hasMany(Certificate::class);
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/models/custom-pivot-table-name.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ class User extends Model

public function accounts()
{
return $this->belongsToMany(\App\Account::class, 'test');
return $this->belongsToMany(Account::class, 'test');
}
}
6 changes: 3 additions & 3 deletions tests/fixtures/models/foreign-key-shorthand-phpdoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ class Comment extends Model
*/
public function post()
{
return $this->belongsTo(\App\Post::class);
return $this->belongsTo(Post::class);
}

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function author()
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(User::class);
}

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function country()
{
return $this->belongsTo(\App\Country::class, 'ccid', 'code');
return $this->belongsTo(Country::class, 'ccid', 'code');
}
}
4 changes: 2 additions & 2 deletions tests/fixtures/models/model-configured.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class Comment extends Model

public function post()
{
return $this->belongsTo(\Some\App\Models\Post::class);
return $this->belongsTo(Post::class);
}

public function author()
{
return $this->belongsTo(\Some\App\Models\User::class);
return $this->belongsTo(User::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public function lines()

public function user()
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(User::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function transaction()

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

public function product()
{
return $this->belongsTo(\App\Product::class);
return $this->belongsTo(Product::class);
}
}
12 changes: 6 additions & 6 deletions tests/fixtures/models/model-relationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,31 @@ class Subscription extends Model

public function teams()
{
return $this->belongsToMany(\App\Team::class);
return $this->belongsToMany(Team::class);
}

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

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

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

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

public function product()
{
return $this->belongsTo(\App\Product::class);
return $this->belongsTo(Product::class);
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/models/nested-models.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ScreeningQuestion extends Model

public function report()
{
return $this->belongsTo(\App\Models\Screening\Report::class);
return $this->belongsTo(Report::class);
}

public function appointmentType()
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/models/post-polymorphic-relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class Post extends Model

public function images()
{
return $this->morphMany(\App\Image::class, 'imageable');
return $this->morphMany(Image::class, 'imageable');
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/models/readme-example-phpdoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ class Post extends Model
*/
public function author()
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(User::class);
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/models/readme-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ class Post extends Model

public function author()
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(User::class);
}
}
4 changes: 2 additions & 2 deletions tests/fixtures/models/relationships-phpdoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class Comment extends Model
*/
public function post()
{
return $this->belongsTo(\App\Post::class);
return $this->belongsTo(Post::class);
}

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function author()
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(User::class);
}
}
4 changes: 2 additions & 2 deletions tests/fixtures/models/relationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class Comment extends Model

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

public function author()
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(User::class);
}
}
8 changes: 4 additions & 4 deletions tests/fixtures/models/return-type-declarations.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ class Term extends Model

public function organizers(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(\App\Organizer::class);
return $this->belongsToMany(Organizer::class);
}

public function events(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(\App\Event::class);
return $this->belongsToMany(Event::class);
}

public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(User::class);
}

public function team(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(\App\Team::class);
return $this->belongsTo(Team::class);
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/models/soft-deletes-phpdoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ class Comment extends Model
*/
public function post()
{
return $this->belongsTo(\App\Post::class);
return $this->belongsTo(Post::class);
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/models/soft-deletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ class Comment extends Model

public function post()
{
return $this->belongsTo(\App\Post::class);
return $this->belongsTo(Post::class);
}
}
4 changes: 2 additions & 2 deletions tests/fixtures/models/unconventional.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class Team extends Model

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

public function manager()
{
return $this->belongsTo(\App\User::class);
return $this->belongsTo(User::class);
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/models/user-polymorphic-relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class User extends Model

public function images()
{
return $this->morphMany(\App\Image::class, 'imageable');
return $this->morphMany(Image::class, 'imageable');
}
}