I always debug my code with var_dump
's and I do var_dump
-ing quite often.
I've been using Laravel for about a month so far, and since the first day I'm having an annoying situation with infinite recursion that makes me restart my computer.
I'm still not sure what is causing this, but probably Eloquent collections. The last piece of code that made me write this question was:
model Applicant.php
public function resumes(){
return $this->hasMany('\MyApp\Resume');
}
I saved $applicant
to a session and in a view I did:
var_dump(Session::get('applicant')->resumes());
I understand the correct way would be ->resumes
, calling it as it was a property not a method, but I'm intrigued to know why this will make my Ubuntu crash, go out of memory, forcing me to restart.
Is there a way to configure artisan to prevent this to happen? Why is it happening?!
@edit
This same problem happens when I do something like without ->get()->all()
var_dump(Model::where('field',$val));
Can you try saving the model key to session instead of the model?
Session::put('applicant_id',$applicant->getKey());
then when to retrieve it
public function getApplicantFromSession() {
static $applicant;
if(is_null($applicant)) {
$applicant = Applicant::find(Session::get('applicant_id'));
}
return $applicant;
}
Then to get the resume's I would use:
public function getApplicantResumes() {
$applicant = $this->getApplicantFromSession();
if(!is_null($applicant)) {
return $applicant->resumes;
}
return collect([]);
}