Tuesday, April 11, 2017

How to solve Call to a member function getDateFormat() on null on the laravel?

I use laravel 5.3

I use this : https://github.com/jenssegers/laravel-mongodb

My query is like this :

public function create(array $attributes)
{
    $result = Employee::create($attributes);
    return $result;
}

My model is like this :

<?php
namespace App\Models;
use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent; 
use Jenssegers\Mongodb\Eloquent\HybridRelations;
class Employee extends Model {
    use HybridRelations;  
    use SoftDeletes;
    protected $connection = 'mongodb';
    public $table = 'employees';
    protected $dates = ['deleted_at'];
    public $fillable = [
        ...
        'nilai'
    ];
    protected $casts = [
        ...
        'nilai' => 'double'
    ];
}

When executed, there exist error like this :

1/1

FatalThrowableError in Model.php line 3031:

Call to a member function getDateFormat() on null

How can I solve it?

When I use mysql, it works

But when I change it use mongodb, there exist error like that



via samuel toh

Advertisement