I'm not sure the issue is with $this->start_time - your hasMany() call references the same column as both local and foreign, therefore the relation should only ever match itself.
Jun 7, 2018
7
Level 4
Self Relation on Model with date Constraint - Possible?
Laravel : 5.2 PHP: 5.6
I am trying to figure out how to ask this...
Is it possible to add a relation to self and then exclude anything newer than the current selection....
I am trying to determine if a call is unique by determining if a Call has Calls before the Current Call- I know crazy way to ask it heh... but basically this...
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Call extends Model
{
public function _previous_calls()
{
return $this->hasMany('App\Call', 'ani', 'ani')->where('start_time', '<', $this->start_time);
}
}
it seems like $this->start_time is not valid because i am eager loading in my controller.
Please or to participate in this conversation.