我想在laravel 5.4上更新我的相关表格
我的代码
<ul class="burger__nav-wrap">
<li class="burger__nav-wrap-item"><a href="<?php echo site_url(); ?>" class="burger__nav-link burger__nav-link_color">Home</a></li>
<li class="burger__nav-wrap-item burger__nav-wrap-item_click"><a href="#" class="burger__nav-link burger__nav-link_click-item">Portfolio+</a>
<ul class="burger__nav-wrap_hidden-menu">
<li class="burger__nav-wrap-item burger__nav-wrap-item_big-margin burger__nav-wrap-item_hidden"><a href="fashion" class="burger__nav-link">Fashion</a></li>
<li class="burger__nav-wrap-item burger__nav-wrap-item_small-margin burger__nav-wrap-item_hidden"><a href="beauty" class="burger__nav-link">Beauty</a></li>
<li class="burger__nav-wrap-item burger__nav-wrap-item_small-margin burger__nav-wrap-item_hidden"><a href="editorial" class="burger__nav-link">Editorial</a></li>
<li class="burger__nav-wrap-item burger__nav-wrap-item_small-margin burger__nav-wrap-item_hidden"><a href="tests" class="burger__nav-link">Tests</a></li>
<li class="burger__nav-wrap-item burger__nav-wrap-item_small-margin burger__nav-wrap-item_hidden"><a href="family" class="burger__nav-link">Family</a></li>
</ul>
</li>
<li class="burger__nav-wrap-item"><a href="blog" class="burger__nav-link burger__nav-link_color">Blog</a></li>
<li class="burger__nav-wrap-item"><a href="about" class="burger__nav-link burger__nav-link_color">About</a></li>
<li class="burger__nav-wrap-item"><a href="contact" class="burger__nav-link burger__nav-link_color">Contact</a></li>
.burger__nav-wrap_hidden-menu {
display: none;
}
.open-menu {
display: block;
}
$(function(){
$(".burger__nav-link_click-item").on("click", function(){
$(".burger__nav-wrap_hidden-menu").toggleClass("open-menu");
});
});
我的代码总是在proposalService中创建一个新行,但不会更新。 如果new和Update如果存在,我怎样才能创建。
答案 0 :(得分:0)
updateOrCreate()
需要2个参数(2个数组)。第一个数组,您传递要检查的元素,通常是主键和其他一些元素。然后,它检查这些元素是否存在,否则,创建一个新元素。
$find->proposalService()->updateOrCreate(
[
'service_item_id' => $request->service_item_id[$key],
'service_type_id' => $request->service_type_id[$key]
],
[
'start_date' => $request->start_date[$key],
'end_date' => $request->end_date[$key],
'vendor_submit' => $request->vendor_submit[$key]
]
);
在这里,我使用service_item_id
和service_type_id
作为第一个参数来检查它们是否已经存在。