【发布时间】:2022-11-04 15:42:55
【问题描述】:
@extends('master') @section("content") <h1>Upload</h1> <form action="upload" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label>Name</label>
<input type="name" name="name" class="form-control" placeholder="Enter Name">
</div>
<div class="form-group">
<label>Price</label>
<input type="price" name="price" class="form-control" placeholder="Enter price">
</div>
<label>Category</label>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Choose
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Item</a>
<br><a class="dropdown-item" href="#">Diamond</a>
<br><a class="dropdown-item" href="#">Akun</a>
</div>
</div>
</div>
<div>
<input type="file" name="file"><br><br></div>
<div>
<button type="submit"> Sell Item</button>
</div> </form> @endsection ```
function upload(Request $req)
{
$products = new Product;
$products->name=$req->name;
$products->price=$req->price;
$products = $req->file('file')->store('Products');
$req->product()->upload([
'file'=> $products
]);
return redirect ('/');
} ```
我无法将其上传到数据库。它说
坏方法调用异常 方法 Illuminate\Http\Request::product 不存在。
我想从表单上传到数据库。在我使用带有播种机的产品数据库之前
【问题讨论】:
-
将 $req 更改为 $request 然后检查。
-
但我做了这个功能上传(请求$req)
-
没有 Stack Overflow 问题需要以“hello”开头;而“任何人都可以帮助我”是不必要的邀请。
-
您不会“上传”到数据库,而是保存到数据库
$product->save()。我建议您阅读文档。