Newer
Older
use App\Action\Functions;
use App\Validation\ArrayValidation;
use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController
{
private function uniqElements(array $array): array {
return array_unique($array, SORT_REGULAR);
#[Route('/', name: 'home')]
public function home(): Response
$arr = [
['laravel', 'php'],
['codeigniter', 'php'],
['laravel', 'php'],
['c++', 'java'],
];
return $this->json($this->uniqElements($arr));
#[Route('/', name: 'home', methods: ['POST'])]
public function home(Request $request): Response
{
$array = $request->get('arr');
$errors = ArrayValidation::validate($array);
if (count($errors) > 0) {
return new Response((string)$errors);
}
$result = $this->functions->prepareMenu($array);
return $this->json($result);