File: /var/www/api_matriculas/app/Repositories/ConfigurationRepository.php
<?php
namespace App\Repositories;
use App\Models\Configuration;
use Exception;
class ConfigurationRepository
{
public function getAll()
{
return Configuration::where('deleted', false)->get();
}
public function getById($id)
{
$register = Configuration::find($id);
if (!$register) {
throw new Exception("Configuración no existe o fue eliminada", 404);
}
return $register;
}
public function getByCode($code, $id = null)
{
if (!$code || empty($code)) {
throw new Exception("Configuración no existe o fue eliminada", 404);
}
$query = Configuration::where('code', $code);
if ($id > 0) {
$query->where('id', '!=', $id);
}
$register = $query->first();
if (!$register) {
return false;
}
return $register;
}
public function updateOrCreate($data)
{
$updateData = Configuration::updateOrCreate(
[
'code' => strLower($data->code)
],
[
'code' => strLower($data->code),
'description' => $data->description,
'data_fields' => $data->data_fields,
'updated_at' => now(),
'user_updated' => auth()->user()->id ?? null
]
);
return true;
}
}