Laravel:在数据库中存储完整图像路径

Jav*_*ved 0 laravel

我想将我的图像上传路径存储在表中。当前它返回

/storage/images/user/business_card/1524811791.jpg"

例如,我想存储完整的访问 URLabc.com/storage/images/user/business_card/1524811791.jpg

我怎样才能做到这一点 ?

图片上传代码:

    if(Input::file('profile_picture'))
        {
            $profilepic = Input::file('profile_picture');
            $filename  = time() . '.' . $profilepic->getClientOriginalExtension();
            $request->file('profile_picture')->storeAs('public/images/user/profile', $filename);
            $accessUrl = Storage::url('images/user/profile'). '/' . $filename;
            $url = Storage::put('public/user/profile/', $filename);
            $saveUserInformation->profile_picture = $accessUrl;
            $saveUserInformation->save();
        }
Run Code Online (Sandbox Code Playgroud)

Ada*_*ski 5

首先,这是不好的做法。想象一下,当您的域发生变化时,您需要在数据库中进行大量工作。因此相对路径更好。

但如果你确实需要绝对路径,你可以使用域:

{{ Request::root() }}
Run Code Online (Sandbox Code Playgroud)

或者

{{ Request::server ("SERVER_NAME") }}
Run Code Online (Sandbox Code Playgroud)

并将其添加到存储路径之前。

祝你好运!