创建和更新Laravel雄辩 [英] Creating and Update Laravel Eloquent
本文介绍了创建和更新Laravel雄辩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
插入新记录或更新不存在的新记录的快捷方式是什么?
What's the shorthand for inserting a new record or updating if it doesn't exist?
<?php
$shopOwner = ShopMeta::where('shopId', '=', $theID)
->where('metadataKey', '=', 2001)->first();
if ($shopOwner == null) {
// Insert new record into database
} else {
// Update the existing record
}
推荐答案
下面是"lu cip"正在谈论的内容的完整示例:
Here's a full example of what "lu cip" was talking about:
$user = User::firstOrNew(array('name' => Input::get('name')));
$user->foo = Input::get('foo');
$user->save();
下面是最新版本的Laravel中文档的更新链接
Below is the updated link of the docs which is on the latest version of Laravel
此处的文档:更新了链接
这篇关于创建和更新Laravel雄辩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文