Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Laravel-Image-Upload in die Datenbank

Zuerst ändern Sie enctype="multipart/form-data" statt enctype="mutlipart/form-data" in Ihrem Formular. Dann geben Sie diesen Code in Ihren Controller ein

public function store(Request $request)
{
  if($request->hasFile('logo')) {
    $img_ext = $request->file('logo')->getClientOriginalExtension();
    $filename = 'company-logo-' . time() . '.' . $img_ext;
    $path = $request->file('logo')->move(public_path(), $filename);//image save public folder
  }
  //You should store only filename not path in db
  Company::create([
    'name' => $request->name,
    'email' => $request->email,
    'logo' => $filename, 
    'website' => $request->website
  ]);

    return redirect('/company/all');
}