2018-09-09 03:26:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Item extends Model
|
|
|
|
{
|
2018-09-11 23:48:09 +00:00
|
|
|
protected $fillable = ['product_id', 'name'];
|
|
|
|
|
|
|
|
public function product()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Product::class);
|
|
|
|
}
|
|
|
|
|
2018-09-12 05:31:03 +00:00
|
|
|
public function users()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(User::class);
|
|
|
|
}
|
|
|
|
|
2018-09-11 23:48:09 +00:00
|
|
|
public function free($product_id, $user_id)
|
2018-09-09 03:26:57 +00:00
|
|
|
{
|
|
|
|
return $query->where([
|
2018-09-11 23:48:09 +00:00
|
|
|
['user_id', $user_id],
|
|
|
|
['product_id', $product_id],
|
2018-09-14 15:52:07 +00:00
|
|
|
['used_by', ''],
|
2018-09-09 03:26:57 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|