Files
voltcerto/app/Http/Controllers/Resources/ResourceController.php
Luis Medon e488ae3342 Add feature tests, unit tests, and configuration for Laravel application
- Created ExampleTest and RoutesTest for basic application response and route testing.
- Implemented IsolatedDatabaseTestCase for isolated database testing.
- Added unit tests for various models and services including Contract, CPE, and LeadDetail.
- Developed request validation tests for CreateClientRequest, UpdateClientRequest, and ContractRequest.
- Introduced Vite configuration for asset management in the Laravel application.
2026-10-29 11:30:06 +00:00

58 lines
1.6 KiB
PHP

<?php
namespace App\Http\Controllers\Resources;
use App\Http\Controllers\Controller;
use App\Services\ResourceService;
use Illuminate\Http\Request;
abstract class ResourceController extends Controller
{
protected string $resource;
protected string $viewPath;
protected string $collectionName;
protected string $itemName;
public function __construct(private ResourceService $resources)
{
}
public function index()
{
return view($this->viewPath . '.index', [$this->collectionName => $this->resources->all($this->resource)]);
}
public function create()
{
return view($this->viewPath . '.add_edit');
}
public function show($id)
{
return $this->edit($id);
}
public function edit($id)
{
return view($this->viewPath . '.add_edit', [$this->itemName => $this->resources->find($this->resource, $id)]);
}
public function store(Request $request)
{
$this->resources->save($this->resource, $request);
return redirect()->route($this->resource . '.index')->with('success', 'Registo criado com sucesso.');
}
public function update(Request $request, $id)
{
$this->resources->save($this->resource, $request, $id);
return redirect()->route($this->resource . '.index')->with('success', 'Registo atualizado com sucesso.');
}
public function destroy($id)
{
$this->resources->delete($this->resource, $id);
return redirect()->route($this->resource . '.index')->with('success', 'Registo eliminado com sucesso.');
}
}