This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\WebService\Almoxarifado\ConectaSus;
|
||||
|
||||
use App\Exceptions\WebService\Almoxarifado\ConectaSus\FabricanteNotFoundException;
|
||||
use App\Models\Cadastro\Fabricante\Fabricante;
|
||||
use App\Services\Service;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class FabricanteService extends Service
|
||||
{
|
||||
public static function index()
|
||||
{
|
||||
return DB::table('cadastro_fabricante AS fabricante')
|
||||
->select([
|
||||
'fabricante.id',
|
||||
'fabricante.nome',
|
||||
'fabricante.cnpj',
|
||||
])
|
||||
->orderBy('fabricante.nome')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function show($id)
|
||||
{
|
||||
$fabricante = self::getFabricanteModel($id);
|
||||
|
||||
return (object) [
|
||||
'id' => $fabricante->id,
|
||||
'nome' => $fabricante->nome,
|
||||
'cnpj' => $fabricante->cnpj,
|
||||
];
|
||||
}
|
||||
|
||||
private static function getFabricanteModel($id)
|
||||
{
|
||||
$fabricante = Fabricante::find($id);
|
||||
|
||||
if (is_null($fabricante)) {
|
||||
|
||||
throw new FabricanteNotFoundException();
|
||||
}
|
||||
|
||||
return $fabricante;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user