Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Difference of using Trait DocumentModel and extending using Mongodb Model #3106

Closed Answered by GromNaN
masterbater asked this question in Q&A
Discussion options

Just want to clarify if there are some drawbacks of using one to the other thanks

You must be logged in to vote

Using MongoDB\Laravel\Eloquent\Model should be preferred:

The trait MongoDB\Laravel\Eloquent\DocumentModel was introduced in order to support 3rd party model classes.

Replies: 1 comment 1 reply

Comment options

Using MongoDB\Laravel\Eloquent\Model should be preferred:

The trait MongoDB\Laravel\Eloquent\DocumentModel was introduced in order to support 3rd party model classes.

You must be logged in to vote
1 reply
Comment options

Will this be ok I know Laravel mongodb also has Auth class I could use, but using DocumentModel would keep things clean.
I run a test of breeze

<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use MongoDB\Laravel\Eloquent\DocumentModel;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
 use DocumentModel,HasFactory, HasRoles, LogsActivity,Notifiable;
 /**
 * The attributes that are mass assignable.
 *
 * @var array<int, string>
 */
 protected $fillable = [
 'name',
 'email',
 'password',
 ];
 /**
 * The attributes that should be hidden for serialization.
 *
 * @var array<int, string>
 */
 protected $hidden = [
 'password',
 'remember_token',
 ];
 /**
 * Get the attributes that should be cast.
 *
 * @return array<string, string>
 */
 protected function casts(): array
 {
 return [
 'email_verified_at' => 'datetime',
 'password' => 'hashed',
 ];
 }
 public function getActivitylogOptions(): LogOptions
 {
 return LogOptions::defaults()
 ->logAll()
 ->logOnlyDirty();
 }
}
Answer selected by masterbater
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /