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' […]

Laravel & NPM installation Steps

July 15, 2020

Create a new laravel project. $ composer create-project –prefer-dist laravel/laravel   my-project (NOTE: if you do not have composer, please install in your machine and make it global. This will make a lot easier) Or Clone the repository from github or your private repo. $ git clone <your repo> Install NPM globally if you haven’t installed that […]