更新图像时,显示以下错误。我无法更新这个laravel5表单。任何人都能找到我的错误吗?
SiteadminController.php第308行中的FatalErrorException: 在null
上调用成员函数isvalid()
我的档案是
控制器
public function siteadmin_update_product(Request $request)
{
$post = $request->all();
$cid=$post['product_id'];
$product_title = $request->input('product_title');
$product_price = $request->input('product_price');
$product_discount_price = $request->input('product_discount_price');
$product_qty = $request->input('product_qty');
$deal_description = $request->input('deal_description');
$select_merchant = $request->input('select_merchant');
$select_shop = $request->input('select_shop');
$product_meta_keyword = $request->input('product_meta_keyword');
$product_meta_description = $request->input('product_meta_description');
$spec_type = $request->input('spec_type');
$specification = $request->input('specification');
$product_size = $request->input('product_size');
$product_image=Input::file('product_image');
$v =validator::make($request->all(),
[
]
);
if($v->fails())
{
return redirect()->back()->withErrors($v->errors());
}
else
{
if($product_image->isvalid())
{
$extension=$product_image->getClientOriginalName();
$move_img = explode('.',$extension);
$fileName=$move_img[0].str_random(8).".".$move_img[1];
$destinationPath = '../assets/productimage/';
$uploadSuccess=Input::file('product_image')->move($destinationPath,$fileName);
$data = array(
'product_title' => $product_title,
'product_price' => $product_price,
'product_discount_price' => $product_discount_price,
'product_qty' => $product_qty,
'select_merchant' => $select_merchant,
'select_shop' => $select_shop,
'product_meta_keyword' => $product_meta_keyword,
'product_meta_description' => $product_meta_description,
'spec_type' => $spec_type,
'specification' => $specification,
'product_size' => $product_size,
'product_image'=> $fileName,
);
$ch=Product_model::update_product($data,$cid);
//$ch=DB::table('le_banner')->where('banner_id',$post['id'])->update($data);
if($ch > 0)
{
Session::flash ('message_update', 'Record Updated Successfully');
return redirect('siteadmin_manageproduct');
}
else
{
return Redirect('siteadmin_editproduct');
}
}
}
}
模型
public static function update_product($data,$cid)
{
return DB::table('le_product')->where('product_id',$cid)->update($data);
}
查看:
<form class="form-horizontal form-label-left" enctype="multipart/form-data" novalidate action="{{action('SiteadminController@siteadmin_update_product')}}" method="POST">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<input type="hidden" class="form-control" name="product_id" value="<?php echo $row->product_id ?>" id="id">
<!-- text input -->
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Product Title*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="name" class="form-control col-md-7 col-xs-12" data-validate-length-range="3" name="product_title" placeholder="Product Title" required="required" type="text" value="<?php echo $row->product_title ?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Select Main Category<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required>
<option value="press">option 1</option>
<option value="net">option 2</option>
<option value="mouth">option 3</option>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Select Sub Category<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required>
<option value="press">option 1</option>
<option value="net">option 2</option>
<option value="mouth">option 3</option>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Select Second Sub Category<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required>
<option value="press">option 1</option>
<option value="net">option 2</option>
<option value="mouth">option 3</option>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Product Quantity*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="name" class="form-control col-md-7 col-xs-12" data-validate-length-range="1" name="product_qty" placeholder="Product Quantity" required="required" type="number" value="<?php echo $row->product_qty ?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Original Price*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="number" class="form-control col-md-7 col-xs-12" data-validate-length-range="2" name="product_price" placeholder="Original Price" required="required" type="number" value="<?php echo $row->product_price ?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Discounted Price*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="number" class="form-control col-md-7 col-xs-12" data-validate-length-range="2" name="product_discount_price" placeholder="Discounted Price" required="required" type="number" value="<?php echo $row->product_discount_price ?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-2 col-sm-3 col-xs-10"></label>
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="chkPassport">
<input type="checkbox" id="chkSelect" checked/> ( Including tax amount )
</label>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-10"></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="number" id="txtUsername" class="form-control col-md-7 col-xs-12" name="product_incometax" placeholder="Tax Amound" value="<?php echo $row->product_incometax ?>" />
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Shipping Amount*</label>
<label class="control-label col-md-2 col-sm-3 col-xs-12" for="chkNo">
<input type="radio" id="chkNo" name="chkPassPort" checked/>
Free
</label>
<label class="control-label col-md-2 col-sm-3 col-xs-12" for="chkYes">
<input type="radio" id="chkYes" name="chkPassPort" />
Amount
</label>
</div>
<div class="item form-group" id="dvPassport1" style="display: none">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Shipping Amount*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="number" id="txtPassportNumber" class="form-control col-md-7 col-xs-12" value="<?php echo $row->product_shippement_amount ?>" name="product_shippement_amount"/>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Description <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<textarea id="textarea" required="required" name="product_description" class="form-control col-md-7 col-xs-12" placeholder="Description" data-validate-length-range="20"><?php echo $row->product_description ?></textarea>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Want to add specification*</label>
<label class="control-label col-md-2 col-sm-3 col-xs-12" for="Yes">
<input type="radio" id="Yes" name="r4" />
Yes
</label>
<label class="control-label col-md-2 col-sm-3 col-xs-12" for="No">
<input type="radio" id="No" name="r4" checked/>
No
</label>
</div>
<div class="item form-group" id="dvPassport2" style="display: none">
<label class="control-label col-md-3 col-sm-2 col-xs-10">Specification*</label>
<div class="col-md-4 col-sm-6 col-xs-12">
<select id="txtPassportNumber1" class="form-control" required value="<?php echo $row->spec_type?>" name="spec_type">
<?php
foreach($specification as $roww)
{?>
<option value="<?php echo $roww->spec_id;?>"><?php echo $roww->specification_name;?></option>
<?php
}
?>
</select>
</div>
<div class="col-md-2 col-sm-6 col-xs-12">
<input type="text" id="txtPassportNumber1" class="form-control col-md-7 col-xs-12" required data-validate-length-range="3" value="<?php echo $row->specification ?>" name="specification"/>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Product Size<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required value="<?php echo $row->product_size ?>" name="product_size">
<?php
foreach($size as $roww)
{?>
<option value="<?php echo $roww->id;?>"><?php echo $roww->size;?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="states">Product Color*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="colorselector" class="form-control">
<option value="red">Red</option>
<option value="yellow">Yellow</option>
<option value="blue">Blue</option>
</select>
</div>
</div>
<div class="item form-group">
<div class="output">
<label class="control-label col-md-3 col-sm-3 col-xs-12"></label>
<div id="red" class="colors red"> <input type="checkbox" checked/>RED </div>
<div id="yellow" class="colors yellow"> <input type="checkbox" checked/> YELLOW</div>
<div id="blue" class="colors blue"><input type="checkbox" checked/> BLUE</div>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Delivery Days*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="number" class="form-control" placeholder="Delivery Days" name="product_days" required value="4" value="<?php echo $row->product_days ?>">
Eg : (2-5)
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Select Merchant<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required value="<?php echo $row->select_merchant ?>" name="select_merchant">
<?php
foreach($merchant as $roww)
{?>
<option value="<?php echo $roww->merchant_id;?>" >
<?php echo $roww->merchant_firstname;?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Select Shop<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required value="<?php echo $row->select_shop ?>"
name="select_shop">
<?php
foreach($merchant as $roww)
{?>
<option value="<?php echo $roww->store_id;?>" >
<?php echo $roww->store_name;?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Meta Keywords
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<textarea id="textarea" name="product_meta_keyword" class="form-control col-md-7 col-xs-12" placeholder="Meta Keywords"><?php echo $row->product_meta_keyword ?></textarea>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Meta Description
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<textarea id="textarea" name="product_meta_description" class="form-control col-md-7 col-xs-12" placeholder="Meta Description"><?php echo $row->product_meta_description ?></textarea>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Product Image </label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="file" name="product_image" value=""><br>
<img src="{{ url('../assets/productimage/').'/'.$row->product_image}}" style="height:90px;">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Product Image </label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="file" name="product_image" value=""><br>
<img src="{{ url('../assets/productimage/').'/'.$row->product_second_image}}" style="height:90px;">
</div>
</div>
<div class="item form-group">
<div class="col-md-3"></div>
<div class="col-md-2 col-sm-6 col-xs-12">
<button class="btn btn-block btn-success" type="submit">Update</button>
</div>
<div class="col-md-2 col-sm-6 col-xs-12">
<button class="btn btn-block btn-danger" type="reset">Cancel</button>
</div>
</div>
</form>
答案 0 :(得分:0)
您有两个名为product_image
的文件输入。这就是你的文件为空的原因,isValid()
会抛出错误。您可以使用hasFile()
来避免此类异常。
答案 1 :(得分:0)
替换
Input::file('image')->isValid()
到
Input::hasFile('image')