我的刀片中有这个:
<div class="row">
<div class="col-sm-6">
<label for="name">Name</label>
<input class="form-control" type="text" id="name" name="name">
</div>
<div class="col-sm-6">
<label for="slug">Slug</label>
<input class="form-control" type="text" id="slug" name="slug">
</div>
</div>
<br>
<div class="row">
<div class="col-sm-6">
<label for="item_type">Item Type</label>
<select class="form-control" id="item_type" name="item_type">
<option value="physical-goods">Physical Goods</option>
<option value="digital-downloads">Digital Downloads</option>
<option value="credits">Credits</option>
</select>
</div>
<div class="col-sm-6">
<label for="order_mode">Order Mode</label>
<select class="form-control" id="order_mode" name="order_mode">
<option value="fcfs">First Come, First Serve</option>
<option value="pre-selling">Pre-Selling</option>
<option value="purchase-order">Purchase Order</option>
</select>
</div>
</div>
<br>
<div>
<label for="short_description">Short Description</label>
<textarea class="form-control" id="short_description" rows="2"></textarea>
</div>
<br>
<div>
<label for="description">Description</label>
<textarea class="form-control" id="description" rows="3"></textarea>
</div>
并且我在我的ProductsController @ Store中拥有它:
$product = Product::firstorCreate([
'name' => $request->input('name'),
'slug' => $request->input('slug'),
'item_type' => $request->get('item_type'),
'order_mode' => $request->get('order_mode'),
'short_description' => $request->input('short_description'),
'description' => $request->input('description')
]);
我的验证:
$this->validate($request, [
'name' => '',
'slug' => '',
'item_type' => 'required',
'order_mode' => 'required',
'short_description' => '',
'description' => ''
]);
,我得到一个错误,要求输入名称和子词,但是我在名称和子词输入中键入了一些内容。 当我尝试删除require字段时,出现错误,并且显示所有输入内容:名称,子句,简短描述和描述都为空。我已经检查了刀片并且检查了他们的名字,为什么会这样?
编辑: 现在我有这个错误:
SQLSTATE [23000]:违反完整性约束:1062重复的条目 ”以获取键“ products_slug_unique”(SQL:插入
products
({name
,slug
,store_id
,item_type
,order_mode
,short_description
,description
,created_by_id
,uuid
,updated_at
,created_at
)个值(,, 36bf3d40-8cb7-11e8-9f9e-5b6a2e94b49b,实物商品,FCFS, dfgdfgdfgdd,dfgdgdfgdfgdf,36bc6160-8cb7-11e8-9381-8b8110d8adde, 4ba43e00-aaa2-11e8-ae40-8983e976b812,2018-08-28 09:11:06,2018-08-28 09:11:06))
因为当我尝试保存时,不需要名称和子词,因此将其保存在数据库中,但是问题是,没有任何保存。它是空白的。所以当我再次尝试保存时,它将出现此错误,因为because是唯一的
答案 0 :(得分:1)
我认为问题在于您接受请求。请尝试:-
$product = Product::firstorCreate([
'name' => $request->name,
'slug' => $request->slug,
'item_type' => $request->item_type,
'order_mode' => $request->order_mode,
'short_description' => $request->short_description,
'description' => $request->description
]);
答案 1 :(得分:0)
您为什么使用:输入和获取?
ssh-keyscan git.comp.com >> ~/.ssh/known_hosts
尝试dd($ request-> all())来查看表单实际发送的内容。
答案 2 :(得分:0)
you can use this
{!! Form::open([ 'route' => ['ProductsController@Store '], 'method' => 'POST' ]) !!}
//on Controller
public function ProductsController@Store($request){
$this->validate($request, [
'name' => 'required',
'slug' => 'required',
'item_type' => 'required',
'order_mode' => 'required',
'short_description' => 'required',
'description' => 'required'
]);
$product = Product::firstorCreate([
'name' => $request->name,
'slug' => $request->slug,
'item_type' => $request->item_type,
'order_mode' => $request->order_mode,
'short_description' => $request->short_description,
'description' => $request->description
]);
}
答案 3 :(得分:0)
我看到有两个问题-
根据文档,您的验证码应类似于-
$this->validate($request, [
'item_type' => 'required',
'order_mode' => 'required',
]);
仅放入需要验证的字段
答案 4 :(得分:0)
我唯一的问题是
<input class="form-control" type="text" id="slug" name="slug">
是我的代码,我缺少一个'/'
<input class="form-control" type="text" id="slug" name="slug"/>
当我添加'/'时,它起作用:)