Code optimisation and minor function fixes

This commit is contained in:
Deon George
2018-12-05 21:50:38 +11:00
parent 3651a6508a
commit 9c2304869d
5 changed files with 372 additions and 239 deletions

View File

@@ -2,10 +2,29 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class Frame extends Model
{
protected static function boot() {
parent::boot();
static::addGlobalScope('order', function (Builder $builder) {
$builder->orderBy('created_at','DESC');
});
}
/**
* Return the Page Number
*
* @return string
*/
public function getPageAttribute()
{
return $this->frame.$this->index;
}
/**
* Fetch a specific frame from the database
*
@@ -13,12 +32,11 @@ class Frame extends Model
* @param string $frame
* @return mixed
*/
public function fetch(int $frame,string $index): \App\Classes\Frame
public function fetch(int $frame,string $index='a'): \App\Classes\Frame
{
// Return our internal test frame.
if ($frame == '999' and $index == 'a')
{
return new \App\Classes\Frame(\App\Classes\Frame::testFrame());
}
return new \App\Classes\Frame($this->where('frame',$frame)->where('index',$index)->firstOrFail());
}