Closed
Description
Laravel v5.3.30
laravel-mongodb v3.2.3
I have 2 collections - one containing vehicles, the other containing statistics (vehicle views)
<?php
namespace App\Collections;
use Jenssegers\Mongodb\Eloquent\Model as Moloquent;
class Vehicle extends Moloquent {
protected $connection = 'mongodb';
protected $fillable = ['manufacturer', 'model', 'colour', 'features', 'branch', 'vin'];
protected $dates = ['date_assigned'];
public function associated_views()
{
return $this->hasMany('App\Collections\Statistic');
}
}
<?php
namespace App\Collections;
use Jenssegers\Mongodb\Eloquent\Model as Moloquent;
class Statistic extends Moloquent {
protected $connection = 'mongodb';
protected $fillable = ['ip', 'event'];
public function associated_vehicle()
{
return $this->belongsTo('App\Collections\Vehicle');
}
}
And I want a simple query to give me a vehicle containing the number of views the vehicle has had:
$vehicle = Vehicle::withCount('associated_views')->find('580f3db65b3914fa56386a33');
echo $vehicle->associated_views_count;
However, this gives me an error:
in Builder.php line 355
at HandleExceptions->handleError('2', 'Illegal offset type', '/var/www/html/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Query/Builder.php', '355', array('columns' => array('vehicles.*' => true), 'wheres' => array('_id' => object(ObjectId)), 'column' => object(Expression))) in Builder.php line 355`
Being able to include the associated_views_count in the results would give my app a huge performance boost, so seriously, any help would be much appreciated!