存储的图像未在Laravel中显示

问题描述

我正在使用Laravel上传和存储图像,但是每当我尝试显示它时,它都会以404答复。

public function uploadPhoto(Request $request){

    $request->validate([
        'doc_photo' => 'file|image|mimes:jpeg,png,gif,webp|max:2048'
    ]);

    $user_id = $request->input('user_id1');
    $usermodel = User::find($user_id);
    
    if($request->has('user_photo')){

        $photo_file = $request->file('user_photo');
        $photo_filename = 'dp_' . $user_id . '.' . $photo_file->getClientOriginalExtension();
        $photo_path = $photo_file->storeAs('DP',$photo_filename);
        $usermodel->display_image_path = $photo_path;

    }

    $result = $usermodel->save();
    toastr()->success("Photo Uploaded","Success");
    
    return back();

}

和我的config / filesystems.PHP看起来像

    'local' => [
        'driver' => 'local','root' => storage_path('app/public'),],'public' => [
        'driver' => 'local','url' => env('APP_URL').'/storage','visibility' => 'public',

并且在html页面显示它时,出现此错误

获取http://xyzdomian.com/storage/app/DP/dp_4.png 404(未找到)

如果我物理上签入该文件夹,则会创建该文件,但仍找不到404。 请指导我解决此问题。

解决方法

控制器

中的更改
config/filesystems.php

更改您的'local' => [ 'driver' => 'local','root' => storage_path('app'),],'public' => [ 'driver' => 'local','root' => storage_path('app/public'),'url' => env('APP_URL').'/storage','visibility' => 'public',

{{1}}