Friday, March 17, 2017

How to define withTrased on model ? (Laravel 5.3)

My model is like this :

<?php
namespace App\Models;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent; 
use Jenssegers\Mongodb\Eloquent\HybridRelations;
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
class Message extends Eloquent
{
    use HybridRelations;  
    use SoftDeletes; 
    protected $connection = 'mongodb';
    protected $dates = ['deleted_at'];
    protected $fillable = ['subject', 'information', 'created_at', 'update_at'];
}

If I get data from model like this :

Message::withTrashed()->find($id);

I success get data with trashed

But I want define it on the model

So when call :

Message::find($id);

It also get data with trashed

How can I do it?



via samuel toh

Advertisement