65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Item extends Model
|
|
{
|
|
|
|
use SoftDeletes;
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'iid', 'uid', 'description', 'eid', 'cid', 'returned_at'
|
|
];
|
|
|
|
|
|
protected $primaryKey = 'iid';
|
|
|
|
/**
|
|
* The attributes excluded from the model's JSON form.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = ['created_at','updated_at', 'deleted_at', 'returned_at', 'eid', 'iid'];
|
|
|
|
public static function restored($callback)
|
|
{
|
|
}
|
|
|
|
public static function create(array $attributes = [])
|
|
{
|
|
$uid = static::query()->where('eid',$attributes['eid'])->max('uid') + 1;
|
|
$attributes['uid'] = $uid;
|
|
static::query()->create($attributes);
|
|
return Item::find($uid);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|