當我使用php unlink方法時,我能夠使用下面的邏輯從本地驅動程式中洗掉圖片,但當我使用Storage facade時,帖子被洗掉,但圖片沒有被洗掉。我試著用Facade的方式進行操作,但我似乎不能讓它發揮作用。我錯過了什么呢?
public function destroy(Post $post)
{
//unlink('storage/'.$post->imagePath);{
Storage::delete('storage/'.$post->imagePath) 。
$post->洗掉()。
return redirect(route('post.index'))->with('flash', 'post Deleted Successfully')。
}
uj5u.com熱心網友回復:
你必須明白,(默認情況下),Storage門面查看/your/project/storage/app。
這就是root目錄。
如果我們假設:
- 你的專案位于
/home/alphy/my-project。
$post->imagePath == 'post/18/picture.png'
...然后:
- 所有的
StorageFacade方法,包括delete(),copy(),path()... 將尋找/home/alphy/my-project/storage/app/posts/18/picture.png當你給他們$post-> imagePath
所以:
public function destroy(Post $post)
{
Storage::delete('storage/'.$post->imagePath) 。
//試圖洗掉/home/alphy/my-project/storage/app/storage/$post->imagePath 。
// which is probably wrong
$post-> delete()。
return redirect(route('post.index'))->with('flash', 'post Deleted Successfully');
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/310318.html
標籤:
