I am trying to return a response of an object which came from a collection array due to a relation of hasMany.
I have tried to do a return $block->where('date','=',$today)->first();
error said: Call to undefined method App\BlockDate::addEagerConstraints()
public function block_dates()
{
return $this->hasMany(BlockDate::class);
}
public function schedule_block()
{
$today = Carbon::today()->toDateString();
$block = $this->block_dates();
return $block->where('date','=',$today)->first();
}
schedule_block() should return an object of BlockDate. If I remove first(), it returns an array with the desired object in. I would like to just retrieve the object based on the relation. Any help is appreciated.
->schedule_block()?