First Or Create

前端 未结 4 1596
耶瑟儿~
耶瑟儿~ 2020-12-02 15:18

I know using:

User::firstOrCreate(array(\'name\' => $input[\'name\'], \'email\' => $input[\'email\'], \'password\' => $input[\'password\']));
         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 15:48

    An update:

    As of Laravel 5.3 doing this in a single step is possible; the firstOrCreate method now accepts an optional second array as an argument.

    The first array argument is the array on which the fields/values are matched, and the second array is the additional fields to use in the creation of the model if no match is found via matching the fields/values in the first array:

    See documentation

提交回复
热议问题