Laravel / Php Carbon Error : Trailing Data
Get the solution ↓↓↓A piece of code that was working fine has now completely thrown me an error that I'm at a lost of figuring out. I'm trying to retrieve a bunch of rows and return them.
The error I'm receiving is
InvalidArgument
Exception Trailing data
in
vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:623
I have seen issues where this is happening on PGSQL and with relation to a date format. However, in my case it's a bit different. My DB is MYSQL.
Below is the method I have.
public function listall()
{
$questions = Question::select('id as qId','questionText','questionCategory','answerType','display','questionOrder','created_at','updated_at')->where('display',1)->orderBy('questionOrder')->with('options')->get();
//$questions = Question::where('display',1)->orderBy('questionOrder')->with('options')->get();
foreach($questions as &$question){
$number = Answers::where('questionId', $question->id)->get();
$question->delete = $number->count() == 0 ? true : false;
}
$data['questions'] = $questions;
$data['categories'] = $this->categories;
$data['answerTypes'] = $this->answerTypes;
return $data;
}
If I do a dd() instead of the return, I can see all data with no errors.
Which means the code execution is working as expected.
I get the same error if I tryreturn json_encode($data);
Instead of selecting all columns with the *, if I mention individual column names as shown in the first line of the function it work as long as if I don't select the id column.
However, if I select the id column the error gets thrown again.
If I doselect id as qId
, then I don't get any errors.
Why would this be happening? Any help is greatly appreciated.
Laravel framework : 6.18.8
Php : 7.4
nesbot/carbon : 2.32.2
Stacktrace in : https://flareapp.io/share/omwQlo7E#F66
Gist at : https://gist.github.com/elabuwa/f9d00d9806134035fc20ec805a8c6498
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: illegal string offset
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.