简体   繁体   中英

Field 'invite' doesn't have a default value Laravel validation

Why does it give such an error? With required_if , I get true or false, and so do I get the string

    public function rules()
    {
        $import = new ServerInviteClient();
        $response = $import->client->request('GET', 'invite');
        $items = $response->getBody()->getContents();

        return [
            'id' => 'required|unique:App\Models\Server,id',
            'content' => 'required|string',
            'invite' => [
                new RequiredIf(str_contains($items, $this->id)),
                'exclude_unless:invite,false|required|string'
            ],
        ];
    }

In my opinion, using Preparing Input is better than this way...

Set a private $isInvatied in class, Check invitation and get $items in preparing, and set as true or false on $this->isInvatied ,

So in rule array due $this->isInvatied value use nullable || required nullable || required rule...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM