我在上传文件时遇到错误,它说未定义变量:filenametostore
。
这是我的控制器:
if(!$validator->fails()){
$cate = Product::where('name','=',$request->product_name)->first();
if($cate){
$arr = array('status'=>'false-1','message'=>'Product name already exist');
}else{
$cat = new Product();
$cat->name = $request->product_name;
$cat->category_id = $request->product_category;
$cat->brand_id = $request->product_brand;
$cat->quantity = $request->product_quantity;
$cat->buy_per_piece = $request->product_buying_per_piece;
$cat->sell_per_piece = $request->product_selling_per_piece;
if($request->hasFile('thumbnail')){
$filenameExt = $request->file('thumbnail')->getClientOriginalName();
$filename = pathinfo($filenameExt,PATHINFO_FILENAME);
$extension = $request->file('thumbnail')->getClientOriginalExtension();
$filenametostore = $filename.'_'.time().'.'.$extension;
$request->file('thumbnail')->move(public_path('images'), $filenametostore);
}
$cat->image = $filenametostore;
$cat->save();
$arr = array('status'=>'true','message'=>'Successfully Inserted');
}
}else{
$arr = array('status'=>'false','message'=>$validator->errors()->all());
}
请帮助我纠正错误