johnvict/error-format

Error-Format 帮助您进行验证,如果存在一个或多个错误,则使用 Laravel 内置验证器返回更令人愉悦的错误对象

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

This package is auto-updated.

Last update: 2024-09-16 00:20:02 UTC


README

Error Format 用于在 laravel/lumen 框架中格式化错误。它将错误对象重构为更易于使用的错误对象

安装

使用 composer 安装 Error Format。

composer require johnvict/error-format

用法

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);
	}
}

贡献

欢迎提交拉取请求。对于重大更改,请先打开一个问题来讨论您想要更改的内容。

许可