GRESPL Nagpur
GRESPL Nagpur

Reputation: 2098

How to get message value from this object

I am getting below output from laravel

I need to get only message from her but unable to get

I am getting this object in $bar variable

FatalThrowableError {#20 ▼
  #message: "Parse error: syntax error, unexpected 'Route' (T_STRING), expecting '{'"
  #code: 0
  #line: 36
  #severity: E_PARSE
  -trace: {▶}
}

I tried $bar->message

Actually I made this error intentionally, I am storing error in table. so I just want to get message part only.

Update

I asked this question because I wanted to to store error in mysql and it is possible through laravel events named illuminate.log it gives two param one for type and another is for message collection with file-name, line number and all, so I asked how to get only message.

Upvotes: 0

Views: 348

Answers (3)

GRESPL Nagpur
GRESPL Nagpur

Reputation: 2098

I am able to get error message by $bar->getMessage(),

I asked this question because I wanted to to store error in mysql and it is possible through laravel events named illuminate.log it gives two param one for type and another is for message collection with file-name, line number and all, so I asked how to get only message.

Upvotes: 0

Jeffrey
Jeffrey

Reputation: 473

Your 'object' is a PHP syntax error. You should check your code for syntax errors. The message attribute is protected (#) and therefore cannot be accessed.

Upvotes: 1

Manvir Singh
Manvir Singh

Reputation: 431

You can use try/catch Block for this purpose please take a look below i am writing a sample code

$response = null;
try{
    //Your Code, Operations
}catch(\Exception $e){
    $response = $e->getMessage();
}
return $response;

Upvotes: 1

Related Questions