首页 文章

使用验证功能的数据库条件的laravel验证

提问于
浏览
1

使用验证功能的数据库条件的laravel验证

我有一个laravel控制器PostContoller和Post模型我想使用数据库表的名称条件

我的表名称发布并使名称唯一,其中post_type = example_post_type_name

请帮忙?

$this->validate($request, [
        'title'     => 'required|max:191',
        'name'      => 'required|max:191|unique:lcf_posts',
        'status'    => 'required|max:191',
    ]);

1 回答

  • 0

    Add Additional Where Clauses:

    $this->validate($request, [
        'title'     => 'required|max:191',
        'name'      => [
                 'required',
                 'max:191',
                 Rule::unique('lcf_posts')->where(function ($query) {
                    return $query->where('post_type ','example_post_type_name');
                 })],
        'status'    => 'required|max:191',
    ]);
    

相关问题