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

File tree

22 files changed

+31
-22
lines changed

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

0 commit comments

Comments
 (0)