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.
46 lines
1.4 KiB
46 lines
1.4 KiB
|
12 months ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Middleware;
|
||
|
|
|
||
|
|
use App\Exceptions\ErrorException;
|
||
|
|
use App\Helpers\ApiResponse;
|
||
|
|
use App\Helpers\ResponseCode;
|
||
|
|
use App\Helpers\StarterResponseCode;
|
||
|
|
use App\Models\CustomForm;
|
||
|
|
use Closure;
|
||
|
|
use Illuminate\Support\Facades\Schema;
|
||
|
|
use Laravel\Sanctum\PersonalAccessToken;
|
||
|
|
|
||
|
|
class BaseForm
|
||
|
|
{
|
||
|
|
use ApiResponse;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Handle an incoming request.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @param \Closure $next
|
||
|
|
* @return mixed
|
||
|
|
*/
|
||
|
|
public function handle($request, Closure $next)
|
||
|
|
{
|
||
|
|
$tableName = request('table_name');
|
||
|
|
if (empty($tableName)) {
|
||
|
|
return $this->fail([StarterResponseCode::START_ERROR_BUSINESS, '表名不存在']);
|
||
|
|
}
|
||
|
|
$customForm = CustomForm::with(['relation' => function ($query) {
|
||
|
|
$query->whereNotNull('link_table_name');
|
||
|
|
}])->with('fields')->where('table_name', $tableName)->first();
|
||
|
|
if (empty($customForm)) {
|
||
|
|
return $this->fail([StarterResponseCode::START_ERROR_BUSINESS, '自定义表不存在']);
|
||
|
|
}
|
||
|
|
$realTable = Schema::hasTable($tableName);
|
||
|
|
if (!$realTable) {
|
||
|
|
return $this->fail([StarterResponseCode::START_ERROR_BUSINESS, '实体表不存在']);
|
||
|
|
}
|
||
|
|
$request->merge(['customForm' => $customForm]);
|
||
|
|
$request->merge(['customFormFields' => $customForm->fields]);
|
||
|
|
return $next($request);
|
||
|
|
}
|
||
|
|
}
|