В laravel 6 приложении у меня есть запрос на магазин, который получает правила из приложения модели / Http / Requests / EventRequest. php определено:
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Event;
class EventRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
$request= Request();
return Event::getValidationRulesArray( $request->get('id') );
}
}
, и я получил ошибку:
LSTATE[42S02]: Base table or view not found: 1146 Table 'CTasksRestAPI.tsk_' doesn't exist (SQL: select count(*) as aggregate from `tsk_` where `id` = 6)",
"exception": "Illuminate\\Database\\QueryException",
"file": "/mnt/_work_sdb8/wwwroot/lar/CTasksRestAPI/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
"line": 669,
"trace": [
и где
CTasksRestAPI - my db name
tsk_ - prefix of db
И моя модель:
<?php
namespace App;
...
class Event extends Model
{
protected $table = 'events';
protected $primaryKey = 'id';
public $timestamps = false;
private static $eventAccessLabelValueArray = Array('P' => 'Private', 'U' => 'Public');
protected $fillable = [
'name', 'access', 'at_time', 'duration', 'task_id', 'description', 'description'
];
...
public static function getEventAccessValueArray($key_return= true, $statusLimitArray=[]) : array
{
$resArray = [];
foreach (self::$eventAccessLabelValueArray as $key => $value) {
if ( !empty($statusLimitArray) ) {
if ( !in_array($key, $statusLimitArray) ) continue;
}
if ($key_return) {
$resArray = Arr::add([$resArray], 'code', $key, 'label', $value);
} else {
$resArray[$key] = $value;
}
}
return $resArray;
}
public static function getValidationRulesArray( $event_id ) : array
{
\Log::info('with(new Event)->getTable() ::');
\Log::info(json_encode( with(new Event)->getTable() ));// I THIS VALUE IN LOG FILE AND SEE VALUE : "events"
$validationRulesArray = [
'name' => [
'required',
'string',
'max:255',
Rule::unique(with(new Event)->getTable())->ignore($event_id),
],
'access' => 'required|in:'.MyFuncsClass::getValueLabelKeys( Event::getEventAccessValueArray(false) ),
'at_time' => 'required',
'duration' => 'required|integer|min:1|max:6000',
'task_id' => 'nullable|exists:'.( with(new Task)->table ).',id',
'description' => 'required',
];
return $validationRulesArray;
}
}
Я полагаю, что проверка уникальности может вызвать ошибку, но почему, поскольку у меня есть поле $ table заполненной модели, и эти «события» должны использоваться в операторе выбора:
protected $table = 'events';
?
Спасибо!