2
@if (file_exists(env('BASE_URL_MASTER').$p->main_image))

<img class="primary-img" src="{{env('BASE_URL_MASTER').$p->main_image}}" alt="single-product" height="200px" width="400px">

@else
<img class="primary-img" src="{{asset($p->main_image?$p->main_image:'')}}" alt="single-product" height="200px" width="400px">
endif

I want to check whether given URL has Image if image is available then @if condition should work. but its not working

Salman Zafar
  • 3,844
  • 5
  • 20
  • 43
kamran
  • 93
  • 11
  • Does this answer your question? [How to check if a file exists from a url](https://stackoverflow.com/questions/7684771/how-to-check-if-a-file-exists-from-a-url) – Dilip Hirapara Mar 13 '20 at 08:23
  • yes but its not working in my case i want to use in blade – kamran Mar 13 '20 at 09:21

1 Answers1

1

Using file_get_content() instead. Example: $file = file_get_content('url_to_file or path_to_file'); if (strlen($file) > 0) 'file exist...'

Doan Duc
  • 23
  • 6