Laravel Customize Failed Validation Request

In this post, I will show you how to customize the form request validates failed response correctly, it’s really simple but useful. <?php namespace App\Http\Requests\Concerns; use App\Enums\Response; use Illuminate\Contracts\Validation\Validator; use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Http\JsonResponse; use Illuminate\Validation\ValidationException; trait HandleFailedValidation { protected function failedValidation(Validator $validator): HttpResponseException { if ($this->expectsJson()) { // if you're json $errors = (new ValidationException($validator))->errors(); // take all errors as array. throw new HttpResponseException( new JsonResponse([ 'status' => Response::FAILED_VALIDATION, // customize status code....

December 3, 2021 · 1 min · Yish

1O1 Started With Hugo

I had used GatsbyJS for two years, for now, I decided to change it. The main reason is, gatsbyjs upgrades from v3 to v4, and also take me having several breaking changes, I almost get errors when I upgrade it, it’s time to focus on my aim: blogging, so I choose Hugo to be my blogging platform, here is my notes when I built it. I read the official documentation, it’s really friendly and easy to read....

December 2, 2021 · 1 min · Yish