PHP – How to make condition if no image show image no image available Laravel

Home / Uncategorized / PHP – How to make condition if no image show image no image available Laravel

Question:
I am newbie in laravel so I really need some help.

I want to make some code if no image available then it will be showing no image available image, this is the example image of no image available http://imgur.com/ppmPcKA

This is my controller to store the image
public function store(CreateBannerRequest $request)
{

$input = $request->all();
//get original file name
$filename = Input::file(‘photo’)->getClientOriginalName();
$input[‘photo’] = $filename;
$banner = $this->BannerRepository->create($input);
//upload file
Input::file(‘photo’)->move($this->path, $filename);

Flash::success(‘Banner saved successfully.’);

return redirect(route(‘banner.index’));
}

And this is the table image code

photo) }} " width="100px" height="100"/>

And this is the view http://imgur.com/a/X4udv

So if no image it will be show No image available


Answer:
You can use Blade conditional

Default text if no image available

@if ($banner->photo)
photo) }} " width="100px" height="100"/>
@else
No image available
@endif

Default image if no image available

photo ? ‘img/banner/’ . $banner->photo : ‘default-image.png’) }} " width="100px" height="100"/>

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *