laravel用刀片显示数据库中的图像

时间:2020-09-21 05:26:31

标签: laravel image laravel-blade

我只是存储了上载到数据库中的图像的路径,但是在表单的编辑部分中,我想显示它,但似乎找不到我尝试过的正确显示方式:

{{HTML :: image('imgs / picture.jpg')}}->此示例正确显示了路径,但 使用-> {!! HTML :: image('product_image')!!}如果我使用chrome开发人员工具检查器,则无法正确显示路径:

import sys

def fahrenheitToCelsius(fahrenheit):
    return (fahrenheit - 32) * 5/9

def celsiusToFahrenheit(celsius):
    return 9/5 * celsius + 32

print("Welcome")

while True:
    userInput = int(input('''\nMain Menu
   1: Fahrenheit to Celsius
   2: Celsius to Fahrenheit
   3: Exit program
   Please enter 1, 2 or 3: '''))

    if userInput == 1:
        fahrenheit = input("\nPlease enter degrees Fahrenheit: ")

        try:
            fahrenheit = float(fahrenheit)
        except ValueError:
            sys.exit("Sorry, {} is not a valid number".format(fahrenheit))

        celsius = fahrenheitToCelsius(fahrenheit)

        print("{} degrees Fahrenheit equals {} degrees Celsius".format(fahrenheit, celsius))

    elif userInput == 2:
        celsius = input("\nPlease enter degrees Celsius: ")

        try:
            celsius = float(celsius)
        except ValueError:
            sys.exit("Sorry, {} is not a valid number".format(celsius))

        fahrenheit = celsiusToFahrenheit(celsius)

        print("{} degrees Celsius equals {} degrees Fahrenheit".format(celsius, fahrenheit))

    elif userInput == 3:
        break

    else:
        print("Invalid entry")

我在做什么错?我想要的是显示存储在数据库中的信息(图像的路径)。

谢谢!

1 个答案:

答案 0 :(得分:0)

使用Storage::url()引用链接https://laravel.com/docs/8.x/filesystem#file-urls

{{ HTML::image(Storage::url('imgs/picture.jpg')) }}
//or
{{ HTML::image(Storage::url($product_image)) }} // here $product_image database path stored by Storage::put() function

它将为laravel这样的存储路径生成url

<img src="http://127.0.0.1:8000/storage/imgs/picture.jpg"> 这是正确的路径