I need to maintain store serial number of topics in db user wise unique, so instead of calculating each time I want to override eloquent create method as
in App\Topic.php
public static function create(array $data)
{
//some logic here
parent::create($data);
}
But whenever I run call Topic::create($data)
method, it fails silently and 500 error
comes on the browser no laravel exception thrown, when I run on tinker, it automatically get an exit , I was unable to find a log where I need to look for this issue
What can be a problem here?
You should do this in the model event instead of overwriting the methods. It does exactly what you need.
public static function boot()
{
parent::boot();
static::creating(function($model) {
// make some changes or log or whatever you want
});
}
You can even move the logic to a custom observer class. Read more about it here https://laravel.com/docs/5.4/eloquent#events