2019-11-15 21:15:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-11-28 23:53:59 +00:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2020-01-05 21:26:18 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2019-11-15 21:15:58 +00:00
|
|
|
|
|
|
|
class Container extends Model
|
|
|
|
{
|
2019-11-28 23:53:59 +00:00
|
|
|
use SoftDeletes;
|
2019-11-15 21:15:58 +00:00
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
2019-11-28 03:52:53 +00:00
|
|
|
'cid', 'name'
|
2019-11-15 21:15:58 +00:00
|
|
|
];
|
|
|
|
|
2019-12-15 17:06:02 +00:00
|
|
|
|
|
|
|
protected $primaryKey = 'cid';
|
|
|
|
|
2019-11-15 21:15:58 +00:00
|
|
|
/**
|
|
|
|
* The attributes excluded from the model's JSON form.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2019-12-02 17:41:40 +00:00
|
|
|
protected $hidden = ['created_at', 'deleted_at', 'updated_at'];
|
2020-01-05 21:26:18 +00:00
|
|
|
|
|
|
|
static function all($columns=Array()){
|
2020-01-17 19:03:24 +00:00
|
|
|
return Container::leftJoin('items','items.cid','=','containers.cid')
|
|
|
|
->select('containers.cid', 'name', DB::raw('count(items.iid) as itemCount'))
|
|
|
|
->groupBy('containers.cid', 'name')->get();
|
2020-01-05 21:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static function find($id){
|
2020-01-17 19:03:24 +00:00
|
|
|
return Container::leftJoin('items','items.cid','=','containers.cid')
|
|
|
|
->select('containers.cid', 'name', DB::raw('count(items.iid) as itemCount'))
|
|
|
|
->groupBy('containers.cid', 'name')->where('items.cid', '=', $id)->first();
|
2020-01-05 21:26:18 +00:00
|
|
|
}
|
2019-11-28 03:52:53 +00:00
|
|
|
}
|