Sunday, March 12, 2017

How can I add soft delete on laravel mongodb? (Laravel 5.3)

I get reference from here : https://github.com/jenssegers/laravel-mongodb#examples

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'];
}

My code to insert is like this:

Message::create([
    'subject'       => $subject,
    'information'   => $information,
    'created_at'    => Carbon::now(),
    'updated_at'    => Carbon::now(),
    'deleted_at'    => null
]);

I try run the code, it success insert to table, but I don't find deleted_at field

How to implement softdelete right on laravel mongodb?



via moses toh

Advertisement