停车场管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
971 B

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Exception;
class BaseController extends Controller
{
/**
* 验证ID
* @param int $id
* @param $model
* @return void
* @throws ValidationException|Exception
*/
protected function validateId(int $id, $model): void
{
$data = ['id' => $id];
$validator = Validator::make($data, [
'id' => 'required|numeric'
], [
'id.required' => __('validation.admin_role.id_empty'),
'id.numeric' => __('validation.admin_role.id_numeric')
]);
if ($validator->fails()) {
throw new ValidationException($validator);
}
if (!$model::query()->where('id', $id)->exists()) {
throw new Exception(__('exception.exception_handler.resource'));
};
}
}