1
我正在使用Laravel 5.4,並且遇到問題。我目前正在將文件上傳功能添加到我的資源產品控制器。這是使用POST和創建和存儲功能以標準方式完成的。 我盯着的代碼,它的工作原理並不像我想要的那樣。 公共職能店($申請要求) {laravel5.4文件上傳問題404 Not Found在此服務器上未找到請求的資源/產品
$product = new Product;
$product->name = $request->name;
$product->primary_category = $request->primary_category;
$product->secondary_category = $request->secondary_category;
$product->price = $request->price;
$product->stock = $request->stock;
$product->low_stock_level = $request->low_stock_level;
$product->location = $request->location;
$product->description = $request->description;
if($request->hasFile('image')){
$product->image = $request->image->storeAs('public',$request->name.'.jpg');
//Storage::putFile('public',$request->file('image'));
//$request->image->path();
//$request->image->store('public');
}
$product->active = 0;
$product->weight = $request->weight;
$product->langth = $request->langth;
$product->width = $request->width;
$product->height = $request->height;
$product->save();
return redirect('products/create');
}
然後我修改了代碼這一點。
公共職能店($申請要求) {
$product = new Product;
$product->name = $request->name;
$product->primary_category = $request->primary_category;
$product->secondary_category = $request->secondary_category;
$product->price = $request->price;
$product->stock = $request->stock;
$product->low_stock_level = $request->low_stock_level;
$product->location = $request->location;
$product->description = $request->description;
if(Input::hasFile('image')){
$file = Input::file('image');
$file->move('products/', $file->getClientOriginalName());
$image = '/products/'.$file->getClientOriginalName();
DB::table('product_images')->insert(
['product_id' => $request->product_id, 'image' => $image]
);
$product->active = 0;
$product->weight = $request->weight;
$product->langth = $request->langth;
$product->width = $request->width;
$product->height = $request->height;
$product->save();
return redirect('products/create');
}
此代碼不起作用巫劑量不是真的關心我。它也會導致這個錯誤。
未找到
所請求的資源/產品並沒有在此服務器上找到。
我敢肯定,這是導致問題的修改,因爲我已經恢復到我最後的穩定版本,並檢查它的工作,然後我修改了代碼,並再次得到相同的錯誤。 甚至在代碼更改爲最後一個穩定版本後,此錯誤仍然存在。
有沒有人有任何想法可能會導致這種情況,我該如何解決這個問題?
感謝您的建議,您好我嘗試在我的最後一個工作版本,不幸的是,我仍然得到同樣的錯誤。 運行有問題的代碼之後,存儲功能不會在表單提交中運行。這將正常指示路線問題,但路線沒有改變。 –