tethys/app/Book.php

51 lines
939 B
PHP
Raw Normal View History

2018-08-06 12:30:51 +00:00
<?php
namespace App;
2015-07-19 06:49:24 +00:00
use Illuminate\Database\Eloquent\Model;
2018-08-06 12:30:51 +00:00
class Book extends Model
{
protected $table = 'books';
protected $fillable = [
'title',
'author',
'year',
'stock',
'project_id'
];
public function project()
{
return $this->belongsTo('App\Project', 'project_id', 'id');
}
// public function shelf()
// {
// return $this->belongsTo('App\Shelf');
// }
public function transactions()
{
//model, foreign key on the Transaction model is book_id, local id
return $this->hasMany('App\Transaction', 'book_id', 'id');
}
public function scopeAvailable($query)
{
return $query->where('stock', '>', 0);
}
public function scopeOrderByTitle($query)
{
return $query->orderBy('title');
}
public function hasProject()
{
return $this->project()->exists();
}
2015-07-19 06:49:24 +00:00
}