我使用Laravel Framework在电子商务网站上进行开发。登录管理面板后,尝试从Product Controller中添加产品名称,产品价格,产品说明。它反复出现上述问题。我的产品控制器出现问题。请尽快给我解决方案。
下面的我的产品Controller.php代码:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Category;
use App\Manufacturer;
use App\Product;
class ProductController extends Controller
{
public function createProduct()
{
$categories=Category::where('publicationStatus',1)->get();
$manufacturers=Manufacturer::where('publicationStatus',1)->get();
return view('admin.product.createProduct',['categories'=>$categories,'manufacturers'=>$manufacturers]);
}
public function storeProduct(Request $request)
{
$this->validate($request,[
'productName'=>'required',
'productPrice'=>'required',
'productImage'=>'required',
]);
$productImage=$request->file('productImage');
$name=$productImage->getClientOriginalName();
$uploadPath='public/productImage/';
$productImage->move($uploadPath,$name);
$imageUrl=$uploadPath.$name;
$this->saveProductInfo($imageUrl);
return redirect('/product/add')->with('message','Product Info Saved Successfully');
}
protected function saveProductInfo($request,$imageUrl)
{
$product = new Product();
$product->productName=$request->productName;
$product->categoryId=$request->categoryId;
$product->manufacturerId=$request->manufacturerId;
$product->productPrice=$request->productPrice;
$product->productQuantity=$request->productQuantity;
$product->productShortDescription=$request->productShortDescription;
$product->productLongDescription=$request->productLongDescription;
$product->productImage =$imageUrl;
$product->publicationStatus=$request->publicationStatus;
$product->save();
}
}
答案 0 :(得分:0)
这行。请删除`符号。
protected function saveProductInfo($request,$imageUrl)
{
` $product = new Product();