Files
unified-restaurant-original/backend/app/Models/Restaurante.php
2021-06-16 03:40:12 -04:00

43 lines
1.0 KiB
PHP

<?php
namespace App\Models;
use App\Models\CanalVenta;
use App\Traits\UuidPrimaryKey;
use App\Exceptions\ModelNotFoundException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log;
/**
* @method static create(array $array)
* @method static find($id)
* @property mixed id
*/
class Restaurante extends Model {
use UuidPrimaryKey, SoftDeletes;
protected $table = 'restaurantes';
protected $fillable = ['id', 'nombre'];
public static function findOrFail($id) {
$restaurante = Restaurante::find($id);
if(!$restaurante){
throw new ModelNotFoundException("restaurant", $id);
}
return $restaurante;
}
public function usuarios() {
return $this->belongsToMany(Usuario::class, 'usuarios_restaurantes', 'restaurante_id', 'usuario_id');
}
public function canalesVenta() {
return $this->hasMany(CanalVenta::class, 'restaurante_id');
}
}