Skip to content

Commit 0600922

Browse files
committed
PHPORM-220 Deprecate using the $collection property to customize the collection name
1 parent 4f2a8df commit 0600922

22 files changed

+31
-22
lines changed

docs/includes/auth/AuthUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class User extends Authenticatable
88
{
99
protected $connection = 'mongodb';
10-
protected $collection = 'users';
10+
protected $table = 'users';
1111

1212
protected $fillable = [
1313
'name',

docs/includes/auth/PersonalAccessToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class PersonalAccessToken extends SanctumToken
1010
use DocumentModel;
1111

1212
protected $connection = 'mongodb';
13-
protected $collection = 'personal_access_tokens';
13+
protected $table = 'personal_access_tokens';
1414
protected $primaryKey = '_id';
1515
protected $keyType = 'string';
1616
}

docs/includes/eloquent-models/PlanetCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
class Planet extends Model
88
{
9-
protected $collection = 'celestial_body';
9+
protected $table = 'celestial_body';
1010
}

docs/includes/fundamentals/read-operations/Movie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
class Movie extends Model
88
{
99
protected $connection = 'mongodb';
10-
protected $collection = 'movies';
10+
protected $table = 'movies';
1111
protected $fillable = ['title', 'year', 'runtime', 'imdb', 'plot'];
1212
}

docs/includes/usage-examples/Movie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
class Movie extends Model
88
{
99
protected $connection = 'mongodb';
10-
protected $collection = 'movies';
10+
protected $table = 'movies';
1111
protected $fillable = ['title', 'year', 'runtime', 'imdb', 'plot'];
1212
}

src/Eloquent/DocumentModel.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@
4646
use function str_contains;
4747
use function str_starts_with;
4848
use function strcmp;
49+
use function trigger_error;
4950
use function var_export;
5051

52+
use const E_USER_DEPRECATED;
53+
5154
trait DocumentModel
5255
{
5356
use HybridRelations;
@@ -141,7 +144,13 @@ public function freshTimestamp()
141144
/** @inheritdoc */
142145
public function getTable()
143146
{
144-
return $this->collection ?? parent::getTable();
147+
if (isset($this->collection)) {
148+
trigger_error('Since mongodb/laravel-mongodb 4.8: Using "$collection" property is deprecated. Use "$table" instead.', E_USER_DEPRECATED);
149+
150+
return $this->collection;
151+
}
152+
153+
return parent::getTable();
145154
}
146155

147156
/** @inheritdoc */

tests/Models/Birthday.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Birthday extends Model
1919
protected $primaryKey = '_id';
2020
protected $keyType = 'string';
2121
protected $connection = 'mongodb';
22-
protected string $collection = 'birthday';
22+
protected $table = 'birthday';
2323
protected $fillable = ['name', 'birthday'];
2424

2525
protected $casts = ['birthday' => 'datetime'];

tests/Models/Book.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Book extends Model
2020
protected $primaryKey = 'title';
2121
protected $keyType = 'string';
2222
protected $connection = 'mongodb';
23-
protected string $collection = 'books';
23+
protected $table = 'books';
2424
protected static $unguarded = true;
2525

2626
public function author(): BelongsTo

tests/Models/Casting.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Casting extends Model
1111
{
1212
protected $connection = 'mongodb';
13-
protected string $collection = 'casting';
13+
protected $table = 'casting';
1414

1515
protected $fillable = [
1616
'uuid',

tests/Models/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Client extends Model
1717
protected $primaryKey = '_id';
1818
protected $keyType = 'string';
1919
protected $connection = 'mongodb';
20-
protected string $collection = 'clients';
20+
protected $table = 'clients';
2121
protected static $unguarded = true;
2222

2323
public function users(): BelongsToMany

tests/Models/Experience.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Experience extends Model
1515
protected $primaryKey = '_id';
1616
protected $keyType = 'string';
1717
protected $connection = 'mongodb';
18-
protected string $collection = 'experiences';
18+
protected $table = 'experiences';
1919
protected static $unguarded = true;
2020

2121
protected $casts = ['years' => 'int'];

tests/Models/Group.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Group extends Model
1515
protected $primaryKey = '_id';
1616
protected $keyType = 'string';
1717
protected $connection = 'mongodb';
18-
protected string $collection = 'groups';
18+
protected $table = 'groups';
1919
protected static $unguarded = true;
2020

2121
public function users(): BelongsToMany

tests/Models/Guarded.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class Guarded extends Model
1414
protected $primaryKey = '_id';
1515
protected $keyType = 'string';
1616
protected $connection = 'mongodb';
17-
protected string $collection = 'guarded';
17+
protected $table = 'guarded';
1818
protected $guarded = ['foobar', 'level1->level2'];
1919
}

tests/Models/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Item extends Model
1818
protected $primaryKey = '_id';
1919
protected $keyType = 'string';
2020
protected $connection = 'mongodb';
21-
protected string $collection = 'items';
21+
protected $table = 'items';
2222
protected static $unguarded = true;
2323

2424
public function user(): BelongsTo

tests/Models/Label.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Label extends Model
2020
protected $primaryKey = '_id';
2121
protected $keyType = 'string';
2222
protected $connection = 'mongodb';
23-
protected string $collection = 'labels';
23+
protected $table = 'labels';
2424
protected static $unguarded = true;
2525

2626
protected $fillable = [

tests/Models/Location.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class Location extends Model
1414
protected $primaryKey = '_id';
1515
protected $keyType = 'string';
1616
protected $connection = 'mongodb';
17-
protected string $collection = 'locations';
17+
protected $table = 'locations';
1818
protected static $unguarded = true;
1919
}

tests/Models/Photo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Photo extends Model
1515
protected $primaryKey = '_id';
1616
protected $keyType = 'string';
1717
protected $connection = 'mongodb';
18-
protected string $collection = 'photos';
18+
protected $table = 'photos';
1919
protected static $unguarded = true;
2020

2121
public function hasImage(): MorphTo

tests/Models/Role.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Role extends Model
1515
protected $primaryKey = '_id';
1616
protected $keyType = 'string';
1717
protected $connection = 'mongodb';
18-
protected string $collection = 'roles';
18+
protected $table = 'roles';
1919
protected static $unguarded = true;
2020

2121
public function user(): BelongsTo

tests/Models/SchemaVersion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SchemaVersion extends Eloquent
1414
public const SCHEMA_VERSION = 2;
1515

1616
protected $connection = 'mongodb';
17-
protected $collection = 'documentVersion';
17+
protected $table = 'documentVersion';
1818
protected static $unguarded = true;
1919

2020
public function migrateSchema(int $fromVersion): void

tests/Models/Scoped.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Scoped extends Model
1515
protected $primaryKey = '_id';
1616
protected $keyType = 'string';
1717
protected $connection = 'mongodb';
18-
protected string $collection = 'scoped';
18+
protected $table = 'scoped';
1919
protected $fillable = ['name', 'favorite'];
2020

2121
protected static function boot()

tests/Models/Skill.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Skill extends Model
1515
protected $primaryKey = '_id';
1616
protected $keyType = 'string';
1717
protected $connection = 'mongodb';
18-
protected string $collection = 'skills';
18+
protected $table = 'skills';
1919
protected static $unguarded = true;
2020

2121
public function sqlUsers(): BelongsToMany

tests/Models/Soft.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Soft extends Model
2121
protected $primaryKey = '_id';
2222
protected $keyType = 'string';
2323
protected $connection = 'mongodb';
24-
protected string $collection = 'soft';
24+
protected $table = 'soft';
2525
protected static $unguarded = true;
2626
protected $casts = ['deleted_at' => 'datetime'];
2727

0 commit comments

Comments
 (0)