c3lf-system-3/app/Item.php

66 lines
1.7 KiB
PHP
Raw Normal View History

2019-11-15 21:26:54 +00:00
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
2019-11-28 03:52:53 +00:00
use Illuminate\Database\Eloquent\SoftDeletes;
2019-11-15 21:26:54 +00:00
class Item extends Model
{
2019-11-28 03:52:53 +00:00
use SoftDeletes;
2019-11-15 21:26:54 +00:00
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
2020-01-18 20:37:02 +00:00
'iid', 'uid', 'description', 'eid', 'cid', 'returned_at'
2019-11-15 21:26:54 +00:00
];
2019-12-15 17:06:02 +00:00
protected $primaryKey = 'iid';
2019-11-15 21:26:54 +00:00
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
2020-01-18 20:37:02 +00:00
protected $hidden = ['created_at','updated_at', 'deleted_at', 'returned_at', 'eid', 'iid'];
2019-12-01 17:30:25 +00:00
2019-12-28 03:31:13 +00:00
public static function restored($callback)
{
}
2020-01-18 19:53:46 +00:00
public static function create(array $attributes = [])
{
2020-01-18 20:55:27 +00:00
$uid = static::query()->withTrashed()->where('eid',$attributes['eid'])->max('uid') + 1;
2020-01-18 20:37:02 +00:00
$attributes['uid'] = $uid;
2020-01-18 20:55:27 +00:00
$item = static::query()->create($attributes);
return Item::find($item->iid);
2020-01-18 19:53:46 +00:00
}
protected static function extended($columns=Array()){
return Item::whereNull('returned_at')
->join('containers','items.cid','=','containers.cid')
->leftJoin('currentfiles','items.iid','=','currentfiles.iid');
}
static function byEvent($eid){
return Item::extended()->where('eid','=',$eid)
->select('items.*','currentfiles.hash as file', 'containers.name as box');
}
static function all($columns=Array()){
return Item::extended($columns)
->select('items.*','currentfiles.hash as file', 'containers.name as box')
->get();
}
static function find($id){
return Item::extended()
->select('items.*','currentfiles.hash as file', 'containers.name as box')
->where('items.iid', '=', $id)->first();
}
2019-11-28 03:52:53 +00:00
}