@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 ('/');
} ```
i cannot upload it to database. its says
BadMethodCallException
Method IlluminateHttpRequest::product does not exist.
i want upload from form to database. before im using product database with seeder
3
Answers
Your view
Your Controller
}
That should work man
Update your code in controller
In the path section you can define your file path, Where you want to upload your file
Update your controller upload() function:
You must have to write this line after your insert query
$products->save();
this line otherwise it could not be store on database. And also you write your file upload path$file->move('uploads/', $filename);
where your file will be uploaded, you could’t define. Your file upload path will be like thisfile->move(public_path('/your file path'), $fileName);
Now, That should work properly.