mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-24 20:26:02 +00:00
Bruno Fontes
882609fed0
Now it shows the username of who is using an item. Item db field 'usedBy' was renamed to 'used_by' to keep consistence.
31 lines
536 B
PHP
31 lines
536 B
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Item extends Model
|
|
{
|
|
protected $fillable = ['product_id', 'name'];
|
|
|
|
public function product()
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
public function users()
|
|
{
|
|
return $this->belongsToMany(User::class);
|
|
}
|
|
|
|
public function free($product_id, $user_id)
|
|
{
|
|
return $query->where([
|
|
['user_id', $user_id],
|
|
['product_id', $product_id],
|
|
['used_by', ''],
|
|
]);
|
|
}
|
|
|
|
}
|