API de restaurante
This commit is contained in:
@@ -5,9 +5,12 @@ namespace App\Models;
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* @method static find(mixed $restaurant)
|
||||
* @method static create(array $array)
|
||||
* @method static find($id)
|
||||
* @property mixed id
|
||||
*/
|
||||
class Restaurante extends Model {
|
||||
@@ -15,6 +18,17 @@ class Restaurante extends Model {
|
||||
|
||||
protected $table = 'restaurantes';
|
||||
|
||||
protected $fillable = ['id', 'nombre'];
|
||||
|
||||
public static function findOrNull($id) {
|
||||
try {
|
||||
return Restaurante::find($id);
|
||||
} catch (QueryException $ex) {
|
||||
Log::warning('Se intento obtener un restaurante con un id invalido', ['id' => $id]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function usuarios() {
|
||||
return $this->belongsToMany(Usuario::class, 'usuarios_restaurantes', 'restaurante_id', 'usuario_id');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user