I'm trying to provide an extra static 'find' method on my eloquent model, shown here:
public static function findBySku($sku)
{
// Using new self; provides the same empty collection results
$instance = new static;
// Using $instance->sku()->newQuery()->get() also returns the same empty collection
$results = $instance->sku()->get();
/*
* This returns an empty collection, however there are records inside the
* relationship database table?
*/
dd($results);
}
So I can use: Inventory::findBySku($sku);
Here's the relationship:
public function sku()
{
return $this->hasOne('Stevebauman\Maintenance\Models\InventorySku', 'inventory_id', 'id');
}
I know the relationship itself isn't the issue because this returns the results from the database table fine:
Inventory::find(1)->sku()->get();
Anyone have any ideas why this doesn't work?
I know it could be because I'm calling a non-static method from a static instance, but why would it return a resulting collection without throwing an error?
Thanks!