I followed this tutorial and created a user model. I would like to create a superclass so that every model has the same timestamp value and a scope method. Is creating a superclass the correct method to do this? How do I extend a custom Eloquent model in Codeigniter?
I have the following idea, but i'm stuck on the custom model extends part.
CustomModel.php:
use \Illuminate\Database\Eloquent\Model as Eloquent;
class CustomModel extends Eloquent {
protected function getDateFormat() {
return 'U';
}
protected function scopeUser($query,$userID) {
return $query->where('user_id','=',$userID);
}
}
User.php:
class User extends CustomModel {
}
I thought about adding a manual include inside the User.php file, but I don't think it is a nice solution. I also prefer not to autoload the CustomModel class.
composer duand using the right namespaces. - Pawel Bieszczad