31 lines
914 B
PHP
31 lines
914 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\UuidPrimaryKey;
|
|
use App\Exceptions\ModelNotFoundException;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class ZonaProduccion extends Model {
|
|
use UuidPrimaryKey, SoftDeletes;
|
|
|
|
protected $table = 'zonas_produccion';
|
|
protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot'];
|
|
protected $fillable = ['id', 'nombre', 'restaurante_id'];
|
|
|
|
public static function findOrFail($id) {
|
|
$zonaProduccion = ZonaProduccion::find($id);
|
|
if(!$zonaProduccion) throw new ModelNotFoundException("zona_produccion", $id);
|
|
return $zonaProduccion;
|
|
}
|
|
|
|
public function restaurante() {
|
|
return $this->belongsTo(Restaurante::class);
|
|
}
|
|
|
|
public function usuarios() {
|
|
return $this->belongsToMany(Usuario::class, 'productores', 'zona_produccion_id', 'usuario_id');
|
|
}
|
|
}
|