Laravel Lumen API Validation in Service Class
February 18, 2021
If you need a validation outside of controller such as service container or service class, below example code may help. Copy traitsĀ ProvidesConvenienceMethods from laravel/lumen-framework/src/Routing to your folder as convenient. Eg, App\Services folder. namespace App\Services\product; use App\Models\Products\Product; useĀ App\Services\ProvidesConvenienceMethods; class ProductCreateService { use ProvidesConvenienceMethods; public function store($request) { // validate request data $product_data = $this->validator($request->all(), [ 'name' […]
Laravel Lumen API Validate Json Array
February 18, 2021
I have this json array as my request data from API. Example input: { “name”: “Test Bundle”, “sku”: “SKU123″, “qty_available”: “2″, “items”:[ { "sku": "SKU123-1", "qty_required": "1", "item_price": "32.00" }, { "sku": "SKU123-2", "qty_required": "1", "item_price": "12.00" } ] } Validation in laravel: // validate request data $bundle_data = $this->validate($request, [ 'name' => 'required|string|min:1|max:255', 'sku' […]
Recent Comments