reconstruction of the project
This commit is contained in:
@@ -7,7 +7,10 @@ use App\Models\BaseModel;
|
||||
class LoginActivity extends BaseModel
|
||||
{
|
||||
protected $table = 'login_activity';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
// ✅ CI: useTimestamps = true (created_at/updated_at)
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'email',
|
||||
@@ -20,18 +23,27 @@ class LoginActivity extends BaseModel
|
||||
'semester',
|
||||
'school_year',
|
||||
];
|
||||
public $timestamps = true;
|
||||
const CREATED_AT = 'created_at';
|
||||
const UPDATED_AT = 'updated_at';
|
||||
|
||||
public function getLastActivities($limit = 4)
|
||||
protected $casts = [
|
||||
'user_id' => 'integer',
|
||||
'login_time' => 'datetime',
|
||||
'logout_time' => 'datetime',
|
||||
];
|
||||
|
||||
/* Optional relationship */
|
||||
public function user()
|
||||
{
|
||||
return $this->orderBy('login_time', 'DESC')->findAll($limit);
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
/**
|
||||
* Equivalent of CI getLastActivities()
|
||||
*/
|
||||
public static function getLastActivities(int $limit = 4)
|
||||
{
|
||||
return static::query()
|
||||
->orderByDesc('login_time')
|
||||
->limit(max(1, $limit))
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user