Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Added Relationship, Scope and Trait
Browse files Browse the repository at this point in the history
  • Loading branch information
nasrulhazim committed Oct 2, 2018
1 parent 1fb7fb4 commit 5492024
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Models/Attendance.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,28 @@ class Attendance extends Model
{
protected $guarded = ['id'];

public function user()
{
return $this->belongsTo(config('attendance.models.user'));
}

public function type()
{
return $this->belongsTo(config('attendance.models.type'))->withDefault();
}

public function scopeTodayEntries($query, $driver = null)
{
if (! is_null($driver)) {
if (is_string($driver)) {
$query->whereDriver($driver);
}

if (is_array($driver)) {
$query->whereIn('driver', $driver);
}
}

return $query->whereDate('created_at', now()->format('Y-m-d'));
}
}
11 changes: 11 additions & 0 deletions src/Traits/AttendanceTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace CleaniqueCoders\Attendance\Traits;

trait AttendanceTrait
{
public function attendances()
{
return $this->hasMany(config('attendance.models.attendance'));
}
}

0 comments on commit 5492024

Please sign in to comment.