Php Laravel显示数据库中的图像
所以我想在视图中显示图像而不是图像名称 这是我的看法Php Laravel显示数据库中的图像,php,laravel,Php,Laravel,所以我想在视图中显示图像而不是图像名称 这是我的看法 <img src="{{$post->image}}" /> 但我仍然得到相同的输出 首先,您必须将图像存储在公共目录中(否则浏览器无法访问它们) 然后它取决于$post->image实际上是什么。如果它是相对于public的路径,则可以执行以下操作: <img src="{{ asset($post->image) }}" /> 编辑 由于您的图像存储在public/img中,并且image属性仅包含
<img src="{{$post->image}}" />
但我仍然得到相同的输出 首先,您必须将图像存储在公共目录中(否则浏览器无法访问它们) 然后它取决于
$post->image
实际上是什么。如果它是相对于public
的路径,则可以执行以下操作:
<img src="{{ asset($post->image) }}" />
编辑
由于您的图像存储在public/img
中,并且image
属性仅包含名称(不包含img/
),因此您必须预先添加以下内容:
<img src="{{ asset('img/' . $post->image) }}" />
image)}}/>
首先,您必须将图像存储在公共目录中(否则浏览器无法访问它们)
然后它取决于$post->image
实际上是什么。如果它是相对于public
的路径,则可以执行以下操作:
<img src="{{ asset($post->image) }}" />
编辑
由于您的图像存储在public/img
中,并且image
属性仅包含名称(不包含img/
),因此您必须预先添加以下内容:
<img src="{{ asset('img/' . $post->image) }}" />
image)}}/>
您可以像这样使用图像)}”/>
您的图像目录是public/img/image的名称您可以这样使用
image}/>
您的映像目录为public/img/image's name映像已保存到数据库中,但您不知道映像保存到磁盘上的哪个文件夹,因此请查看控制器以查看其保存位置 然后在blade中,您可以使用:
<img src="/folder_name_path/{{$post ->image}}" />
image}}/>
图像已保存到数据库中,但您不知道图像保存到磁盘上的哪个文件夹,因此请查看控制器以查看其保存位置
然后在blade中,您可以使用:
<img src="/folder_name_path/{{$post ->image}}" />
image}}/>
public function store(Request $request)
{
$pages = new Appsetting();
$pages->title = $request->input('title');
$pages->description = $request->input('description');
if ($request->hasfile('image')) {
$file = $request->file('image');
$extension = $file->getClientOriginalExtension(); // getting image extension
$filename = time() . '.' . $extension;
$file->move('uploads/appsetting/', $filename);
//see above line.. path is set.(uploads/appsetting/..)->which goes to public->then create
//a folder->upload and appsetting, and it wil store the images in your file.
$pages->image = $filename;
} else {
return $request;
$pages->image = '';
}
$pages->save();
return redirect('pagesurl')->with('success', 'App Setting Added');
}
public function index()
{
$pages = Appsetting::all();
return view('admin.appsettings.pages', compact('pages',$pages));
}
pages.blade.php
)
@foreach($page为$page)
图像)}}}”/>
@endforeach
public function store(Request $request)
{
$pages = new Appsetting();
$pages->title = $request->input('title');
$pages->description = $request->input('description');
if ($request->hasfile('image')) {
$file = $request->file('image');
$extension = $file->getClientOriginalExtension(); // getting image extension
$filename = time() . '.' . $extension;
$file->move('uploads/appsetting/', $filename);
//see above line.. path is set.(uploads/appsetting/..)->which goes to public->then create
//a folder->upload and appsetting, and it wil store the images in your file.
$pages->image = $filename;
} else {
return $request;
$pages->image = '';
}
$pages->save();
return redirect('pagesurl')->with('success', 'App Setting Added');
}
public function index()
{
$pages = Appsetting::all();
return view('admin.appsettings.pages', compact('pages',$pages));
}
pages.Blade.php
)
@foreach($page为$page)
图像)}}}”/>
@endforeach
如果您的图像位于公用/images文件夹中,请使用下面的路径。否则,请使用公用文件夹中该图像的project中的路径。与图像扩展名连接
image}}.jpg“alt={{{$post->image}}/>
如果您的图像位于公用/images文件夹中,请使用下面的。否则,请使用公用文件夹中该图像的项目路径。与图像扩展名连接
image}}.jpg“alt={{{$post->image}}/>
style=“url(背景图像:images/bg.jpg)
在这种情况下如何获取图像style=“url(背景图像:images/bg.jpg)
如何获取图像在这种情况下,函数将生成指向公共目录的绝对URI。通常类似于:
http://example.com/path/you/passed
是结果。好的,我现在明白了,但它仍然不起作用。我不知道我做错了什么。你的图像存储在哪里,$post->image
返回什么?在公共场合/img/和$post->image返回照片的名称。asset
函数将生成指向公共目录的绝对URI。通常类似于:http://example.com/path/you/passed
是结果。好的,我现在明白了,但它仍然不起作用。我不知道我做错了什么。你的图像存储在哪里,$post->image
返回什么?在公共场合/img/和$post->image返回照片的名称。你应该避免在公共场合提问答案,发布一个新问题链接到此问题您应该避免在回答中提问,发布一个新问题链接到此问题