我似乎无法让我的代码100%运行。我试图让我的代码以这样的方式工作:
如果列值为空($id = columnName
),则插入该行。如果有一个"值"找到$id
,然后更新已保存在数据库中的值。
功能:
$socialCheck = SocialSettings::where($id)->first();
$socialInsert = new SocialSettings;
$value = Request::input('value');
if(SocialSettings::where_not_null($id)){
$socialInsert->$id = $value;
$socialInsert->save();
}else{
$socialCheck->update($value);
}
}
答案 0 :(得分:1)
以下是类似问题的例子
SELECT ShopOrder.OrderDate
, Book.BookID
, Book.title
, COUNT(ShopOrder.ShopOrderID) AS "Total number of order"
, SUM (Orderline.Quantity) AS "Total quantity"
, Orderline.UnitSellingPrice * Orderline.Quantity AS "Total order value"
, book.Price * Orderline.Quantity AS "Total retail value"
FROM ShopOrder
JOIN Orderline
ON Orderline.ShopOrderID = ShopOrder.ShopOrderID
JOIN Book
ON Book.BookID = Orderline.BookID
JOIN Publisher
ON Publisher.PublisherID = Book.PublisherID
WHERE Publisher.name = 'Addison Wesley'
GROUP
BY ShopOrder.OrderDate
, Book.BookID
, Book.title
, Orderline.UnitSellingPrice
, Orderline.Quantity, book.Price
, Orderline.Quantity, ShopOrder.ShopOrderID
ORDER
BY ShopOrder.OrderDate
喜欢这个
$user = User::firstOrNew(array('name' => Input::get('name')));
$user->foo = Input::get('foo');
$user->save();
firstOrNew Laravel API DOCS