2017-09-22 59 views

回答

1

我相信,當您使用相對URL在瀏覽器中的轉換路徑將是http://localhost/mywebsite/public/item/{$item_id}/uploads/avatars/{{ Auth::user()->avatar }}

而這不是你要

嘗試

<img src="http://localhost/mywebsite/public/uploads/avatars/{{ Auth::user()->avatar }}"> 

在產量將只是

<img src="/uploads/avatars/{{ Auth::user()->avatar }}"> 

我不知道它會在XAMPP的工作,雖然

這麼說來,我建議使用Laravel代客或宅基地,而不是XAMPP的,它減少像你這樣的一些問題了。

+0

我想要什麼? –

+0

@JohnDoe你會想用'public_path()'來構造正確的URL,可能與'asset()'helper結合在一起。 – ceejayoz

+0

你剛加了一個'/'我也試過那個,沒有工作。謝謝你的回覆 –

-2
在文件模型

我創建了一個函數來獲取刀片文件base64編碼

public function getFile() 
{ 
    $path = storage_path('app'). "/" . $this->path; 
    $type = File::mimeType($path); 

    $file = Storage::disk('local')->get("/". $this->path); 

    return "data:image/png;base64,".base64_encode($file); 
} 

您可以使用這樣的

<img src = '$file->getFile()'> 
+0

Whaaaaat?這是一個可怕的想法。被瀏覽器緩存,佔用1/3多個字節... – ceejayoz

+0

haha​​ha我知道,但我有時使用它來顯示小圖像 – BugraDayi