This is my Product Controller
namespace App\Http\Controllers; use Illuminate\Http\Request;
class ProductController extends Controller { public function index(){
}
public function create(){
return view('admin.products.create');
}
public function store(Request $request){
// validate the form
$request->validate([
'name'=>'required',
'price'=>'required',
'description'=>'required',
'image'=>'image|required'
]);
// upload the image
if($request->hasFile('image')){
$image=$request->image;
$image->move('uploads',$image->getClientOriginalName());
}
// save the data into database
Product::create([
'name'=>$request->name,
'price'=>$request->price,
'description'=>$request->description,
'image'=>$request->image->getClientOriginalName()
]);
// session message
$request->session()->flash('msg','Your Product has been added');
// redirect
return redirect('products/create');
}
I am not able to upload and save data on mysql database}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire