
在反馈表中将有一个整数列。
用户可以输入1,4,5作为反馈。如何设计这一栏在拉拉迁移?
我想到的是json列,它不符合我的整数列的目的。
发布于 2022-03-09 18:56:11
发布于 2022-03-09 19:13:58
如果不想使用多对多的关系,只需将列设为整数,并使用模型来控制列的存储方式。
class Feedback extends Model{
/**
* list of types
*/
const TYPES = [
self::LEADERSHIP => 'Leadership',
self::BOLDNESS => 'Boldness',
self::EXTERNAL_MIND => 'External mind',
...
];
// Define constants
const LEADERSHIP = 1;
const BOLDNESS = 2;
const EXTERNAL_MIND = 3;
...
}迁徙
use App\Models\Feedback;
...
Schema::create('feedbacks', function (Blueprint $table) {
$table->id();
...
$table->tinyInteger('type')->default(Feedback::LEADERSHIP);
});用于验证
use Illuminate\Validation\Rule;
use App\Models\Feedback;
...
Validator::make($data, [
'type' => [
'required',
Rule::in(Feedback::TYPES),
],
]);https://stackoverflow.com/questions/71414525
复制相似问题