As you can see, responses() does not return an instance of your model, rather the Response Facade. You should either rename your model or set a namespace for reference in your Ticket model.
Response.php
<?php namespace My\Models;
class Response extends \Eloquent {}
Ticket.php
<?php namespace My\Models;
class Ticket extends \Eloquent
{
public function responses()
{
return $this->hasMany('My\Models\Response');
}
}
Now $ticket->responses() returns an instance of your model.
ChrisRM said:
As you can see,
responses()does not return an instance of your model, rather theResponseFacade. You should either rename your model or set a namespace for reference in your Ticket model.Response.php
<?php namespace My\Models; class Response extends \Eloquent {}Ticket.php
<?php namespace My\Models; class Ticket extends \Eloquent { public function responses() { return $this->hasMany('My\Models\Response'); } }Now
$ticket->responses()returns an instance of your model.
Thanks. I tried both solutions and they both worked. However, I'm curious why at first responses() couldn't return the instance of my Response model.
Thanks.
Michaelzlies said:
Thanks. I tried both solutions and they both worked. However, I'm curious why at first responses() couldn't return the instance of my Response model.
Thanks.
Response is actually a Laravel Facade, so the naming clashed. Keep that in mind when creating Models and Controllers with no namespacing.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.