Laravel Eloquent Ask Question の作成と更新

Laravel Eloquent Ask Question の作成と更新

新しいレコードを挿入したり、既存のレコードを更新したりするための省略形は何ですか?

<?php

$shopOwner = ShopMeta::where('shopId', '=', $theID)
    ->where('metadataKey', '=', 2001)->first();

if ($shopOwner == null) {
    // Insert new record into database
} else {
    // Update the existing record
}

ベストアンサー1

「lu cip」が話していた内容の完全な例は次のとおりです。

$user = User::firstOrNew(array('name' => Input::get('name')));
$user->foo = Input::get('foo');
$user->save();

以下は、Laravelの最新バージョンのドキュメントの更新されたリンクです。

ドキュメントはこちら:更新されたリンク

おすすめ記事