2017-07-23 34 views
-1

我为我的幼虫项目使用宅基地。目前我正在尝试将图像存储到我的存储文件夹和数据库中的路径中。Laravel Homestead保存图像逻辑

功能如下:

public function create(Request $request) 
    { 
     $data = $request->all(); 
     $file = $request->file('category_avatar'); 
     $file->store('category_images'); 
     $location = storage_path('app/' . $file->store('category_images')); 

     $category = new Category; 
     $category->category_avatar = $location; 
     $category->fill($data); 
     if($category->save()) 
     { 
      return redirect()->route('category.index')->with('message', 'Success'); 
     } 
     else 
     { 
      return redirect()->route('category.index')->with('error', 'Error.'); 
     } 
    } 

映像文件成功被复制的内部存储/应用程序,但不知何故,到路径,我保存到我的数据库是错误的:

目前我获得以下路径在我的数据库:

/tmp/phpwOyIzA 

如果我dd($location);我获得以下的输出:

"/home/vagrant/code/myapp/storage/app/category_images/S4S5ml0XtsiBm6wLa4stQzTXZrEDzFf4egRljDjA.jpeg" 

回答

0

只是删除此行

$file->store('category_images'); 

因为下面的代码足够

+0

仍然不能正常工作,但它仍然保存像这样的/ tmp/phpwOyIzA – 35Hunne

+0

怪异。尝试'dd($ request-> file('category_avatar') - > store('category_images'))'结果是什么?我使用相同的代码并按预期运行 – bhill77