Validaciones y Zonas de produccion

This commit is contained in:
2021-07-12 11:05:50 -04:00
parent 4f1dfd1221
commit d64dacee8d
9 changed files with 186 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use App\Models\CanalVenta;
use App\Models\Sector;
use App\Models\ZonaProduccion;
use App\Traits\UuidPrimaryKey;
use App\Exceptions\ModelNotFoundException;
use Illuminate\Database\Eloquent\Model;
@@ -35,4 +36,8 @@ class Restaurante extends Model {
public function sectores() {
return $this->hasMany(Sector::class, 'restaurante_id');
}
public function zonasProduccion() {
return $this->hasMany(ZonaProduccion::class, 'restaurante_id');
}
}

View File

@@ -22,4 +22,8 @@ class Sector extends Model {
public function restaurante() {
return $this->belongsTo(Restaurante::class);
}
public function canalesVenta() {
return $this->hasMany(CanalVenta::class, 'sector_id');
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Models;
use App\Traits\UuidPrimaryKey;
use App\Exceptions\ModelNotFoundException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -10,6 +11,13 @@ class ZonaProduccion extends Model {
use UuidPrimaryKey, SoftDeletes;
protected $table = 'zonas_produccion';
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);