bookinventory/app/Models/Book.php
2020-12-27 04:29:52 -05:00

62 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use App\Services\Search\BookConfigurator;
use Bnb\Laravel\Attachments\HasAttachment;
use Illuminate\Database\Eloquent\Model;
use ScoutElastic\Searchable;
class Book extends Model {
use Searchable, HasAttachment;
protected $indexConfigurator = BookConfigurator::class;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'location_id', 'barcode', 'name',
];
protected $casts = [
'published_date' => 'datetime:Y-m-d'
];
public function authors() {
return $this->belongsToMany(Author::class, 'book_authors');
}
public function location() {
return $this->belongsTo(Location::class);
}
protected $mapping = [
'properties' => [
'name' => [
'type' => 'text',
'fields' => [
'raw' => [
'type' => 'keyword',
]
]
],
'description' => [
'type' => 'text',
'fields' => [
'raw' => [
'type' => 'keyword',
]
]
],
'published_date' => [
'type' => 'date',
'format' => 'yyyy-MM-dd'
]
]
];
}