Search code examples
laravellaravel-7

How to use error in Laravel 7 in program?


Error Image In Laravel

I want use that error in my code, ex.

if(Not Found In Database) then
show alert"Data Not Found In Database"

How to make that error include to my variabel?

*Note: I'm using Laravel-7


Solution

  • You can try

    throw new \Exception("error");
    

    Edit, adding function for check exist file by use curl

    function checkUrlExistFile($url): bool {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HEADER, true);
      curl_setopt($ch, CURLOPT_NOBODY, true);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10);
      curl_exec($ch);
      $info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);
      if($info == '200') return true;
      return false;
    }
    

    And Example

    if (!checkUrlExistFile($url)) {
      throw new \Exception("error");
    }