Laravel Customize Query Builder

For my situation, I need to use complex query conditions for my cases, I want to aggregate my conditions in my entity, so I decided to extend the query builder. We know laravel providing the method to allow you customize Eloquent builder: newEloquentBuilder, but I want to more easy to use, almostly, I want to out of the box. So I鈥檓 following below to think, starting with my ideal. Model class User extend Model // you can set the contract....

December 4, 2021 路 2 min 路 Yish

Laravel Customize Failed Validation Request

In this post, I will show you how to customize the form request validates failed response correctly, it鈥檚 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鈥檚 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鈥檚 really friendly and easy to read....

December 2, 2021 路 1 min 路 Yish