johnvict/error-format

Error-Format helps you do validation and returns a more pleasing error object if there is one or more, using Laravel In-built Validator

v0.0.3 2020-10-15 15:57 UTC

This package is auto-updated.

Last update: 2024-06-15 23:53:33 UTC


README

ERROR FORMAT

Error Format is used to format error on laravel/lumen framework. It restructures the error object to a simpler-to-use error object

Installation

Use composer to install Error Format.

composer require johnvict/error-format

Usage

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Johnvict\ErrorFormat\Services\ErrorFormat;

class ExampleController extends Controller
{
	/**
	 * Add the ErrorFormat trait to your controller to enable the use of validate request as part of the controller class
	 */
	use ErrorFormat;

    public function home(Request $request) {
		// You can define an array of your validation rule
		$errorRule = [
			"name" => "required|string",
			"phone" => "required|string",
			"username" => "required|string",
			"email" => "email"
		];
		// call the validateRequest as follows
		$error = self::validateRequest($request, $errorRule);
		return response()->json($error);
	}
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License