so i wanted to display the image not the image name in my views.
i got this in my views
image}}\" />
The image was saved to the database, but you don't know which folder on disk the image was saved to, so look on your controller to see where it is saved.
Then in blade you can use:
<img src="/folder_name_path/{{$post ->image}}" />
style="url(background-image:images/bg.jpg) how to fetch image in this case
You can use like this <img src="{{ asset('img')}}/{{ $post->image) }}" />
Your image directory is public/img/image's name
if your image is in public/images folder use below.otherwise use the path in project for that image in the public folder.concatenate with the image extension.
<img src="images/{{$post->image}}.jpg" alt={{$post->image}}/>
First, you have to store the images in the public directory (if not the browser can't access them)
Then it depends what $post->image
actually is. If it is a path relative to public
you can do this:
<img src="{{ asset($post->image) }}" />
Or:
{{ HTML::image($post->image, '', array('class' => 'image')); }}
Since you're images are stored in public/img
and the image
attribute only holds the name (without img/
) you have to prepend that:
<img src="{{ asset('img/' . $post->image) }}" />
Insert Your 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');
}
Display it by index
public function index()
{
$pages = Appsetting::all();
return view('admin.appsettings.pages', compact('pages',$pages));
}
Come to Blade file. (pages.blade.php
)
@foreach ($pages as $page)
<td> <img src="{{ asset('uploads/appsetting/' . $page->image) }}" /> </td>
@endforeach
set your route and 100% working.