如何从请求类 Laravel 中删除项目

时间:2020-12-22 19:39:57

标签: php laravel

当我更新记录并且新的 fetchData(event, rowData.Codigo).then(function (response) { console.log(response); }); 等于旧的 slug 时,我想从 $request 中删除 slug! (因为我使用 slug 来检查 slug 在表中是否唯一,但它失败了!)

2 个答案:

答案 0 :(得分:2)

您可以在不删除字段的情况下执行此操作。例如,如果您正在使用验证请求,您可以像这样忽略唯一性检查:

// don't forget to use this in the top of your class-file
use Illuminate\Validation\Rule;

public function rules()
{
    // for your case replace the word "post"s if need for your appropriate table
    return [
        'slug' => ['required', Rule::unique('posts')->ignore($this->post()->id)]
    ];
}

答案 1 :(得分:-1)

我找到了解决方案!我们可以使用 $requst->requst->remove('slug');