Welcome Guest, Not a member yet? Register   Sign In
Entity auto convert column to time instance on joined table ?
#1

Can an Entity class convert to time instance a joined table column ? i use this query below and want the auth_logins.date to be converted to Time instance if possible

PHP Code:
$model model(UserModel::class);

 
// Users with last login date and success
 
$users $model->select("users.*, auth_logins.date, auth_logins.success")
 
  ->join('auth_logins''auth_logins.user_id = users.id''left outer')
 
  ->where('(SELECT MAX(`id`) FROM `auth_logins` WHERE `auth_logins`.`user_id` = `users`.`id` ) IS NULL'nullfalse)
 
  ->orWhere('`auth_logins`.`id` = (SELECT MAX(`id`) FROM `auth_logins` WHERE `user_id` = `users`.`id`)'nullfalse)
 
  ->findAll($perPage$start); 

I try to add the date column in the entity class

PHP Code:
    /**
    * Define properties that are automatically converted to Time instances.
    */
    protected $dates = ['reset_at''reset_expires''created_at''updated_at''deleted_at''date']; 
Reply
#2

Yes, property names included in the $dates array will be converted to Time instances when possible upon access.
Reply
#3

Thanks Paul it works
I used the php spark publish:auth from Myth Auth, but modification in App\Entity\User have no effect, modifiying the Myth\Auth\Entities works fine.
I'm not very experimented with namespacing and extending files, do you know why editing App\Entity\User have no effect ? I can open another thread or a bug report on github if needed.
Reply
#4

You can open another thread. Then show the contents pf your User entity.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB