<i id='WVsGu'><tr id='WVsGu'><dt id='WVsGu'><q id='WVsGu'><span id='WVsGu'><b id='WVsGu'><form id='WVsGu'><ins id='WVsGu'></ins><ul id='WVsGu'></ul><sub id='WVsGu'></sub></form><legend id='WVsGu'></legend><bdo id='WVsGu'><pre id='WVsGu'><center id='WVsGu'></center></pre></bdo></b><th id='WVsGu'></th></span></q></dt></tr></i><div id='WVsGu'><tfoot id='WVsGu'></tfoot><dl id='WVsGu'><fieldset id='WVsGu'></fieldset></dl></div>
    <legend id='WVsGu'><style id='WVsGu'><dir id='WVsGu'><q id='WVsGu'></q></dir></style></legend>

        <bdo id='WVsGu'></bdo><ul id='WVsGu'></ul>

      <small id='WVsGu'></small><noframes id='WVsGu'>

    1. <tfoot id='WVsGu'></tfoot>

    2. Laravel 5.5 对具有不同列名的单独表的唯一验证规

      时间:2023-09-24
    3. <small id='2GIyM'></small><noframes id='2GIyM'>

        <tbody id='2GIyM'></tbody>

      <i id='2GIyM'><tr id='2GIyM'><dt id='2GIyM'><q id='2GIyM'><span id='2GIyM'><b id='2GIyM'><form id='2GIyM'><ins id='2GIyM'></ins><ul id='2GIyM'></ul><sub id='2GIyM'></sub></form><legend id='2GIyM'></legend><bdo id='2GIyM'><pre id='2GIyM'><center id='2GIyM'></center></pre></bdo></b><th id='2GIyM'></th></span></q></dt></tr></i><div id='2GIyM'><tfoot id='2GIyM'></tfoot><dl id='2GIyM'><fieldset id='2GIyM'></fieldset></dl></div>
      • <tfoot id='2GIyM'></tfoot>

            <bdo id='2GIyM'></bdo><ul id='2GIyM'></ul>

            1. <legend id='2GIyM'><style id='2GIyM'><dir id='2GIyM'><q id='2GIyM'></q></dir></style></legend>
              1. 本文介绍了Laravel 5.5 对具有不同列名的单独表的唯一验证规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                所以我有用户和公司.一个用户属于一个公司.

                So I have users and companies. A user belongs to one company.

                我想验证用户注册,以便他们用来注册的 business_name 字段在 companys 表中是唯一的,目标是不允许用户创建重复公司.

                I want to validate a user registration so that the business_name field they use to register is unique in the companies table, the goal is to not allow users from creating duplicate companies.

                这是我的注册函数:

                public function register(Request $request)
                    {
                        $validator = Validator::make($request->all(), [
                            'first_name' => 'required',
                            'last_name' => 'required',
                            'business_name' => 'required|unique:companies',
                            'email' => 'required|email|max:255|unique:users',
                            'password' => 'required|min:6',
                        ]);
                
                
                        if ($validator->fails()) {
                            return response()->json(['error'=>$validator->messages()], 401);
                        }
                
                }
                

                我要比较的字段是用于检查唯一性的 companies.name.

                The field I want to compare against is the companies.name to check for uniqueness.

                这可能吗?目前它正在尝试在 companys 表中查找 business_name.

                Is this possible? At the moment it is trying to look for business_name in the companies table.

                推荐答案

                没关系,设法弄明白了.只需要一个额外的参数来指定列名:

                Never mind, managed to figure it out. Just needed an extra parameter to specify the column name:

                'business_name' => 'required|unique:companies,name',
                

                这篇关于Laravel 5.5 对具有不同列名的单独表的唯一验证规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:两个外键,如何用laravel eloquent映射 下一篇:Laravel - Eloquent - 动态定义的关系

                相关文章

                最新文章

                  <i id='tdCpl'><tr id='tdCpl'><dt id='tdCpl'><q id='tdCpl'><span id='tdCpl'><b id='tdCpl'><form id='tdCpl'><ins id='tdCpl'></ins><ul id='tdCpl'></ul><sub id='tdCpl'></sub></form><legend id='tdCpl'></legend><bdo id='tdCpl'><pre id='tdCpl'><center id='tdCpl'></center></pre></bdo></b><th id='tdCpl'></th></span></q></dt></tr></i><div id='tdCpl'><tfoot id='tdCpl'></tfoot><dl id='tdCpl'><fieldset id='tdCpl'></fieldset></dl></div>
                1. <small id='tdCpl'></small><noframes id='tdCpl'>

                    <tfoot id='tdCpl'></tfoot>
                  1. <legend id='tdCpl'><style id='tdCpl'><dir id='tdCpl'><q id='tdCpl'></q></dir></style></legend>

                      <bdo id='tdCpl'></bdo><ul id='tdCpl'></ul>