I have a model:
class MyModel extends Model
{
use HasFactory;
public function rel()
{
return $this->hasMany(MyModel2::class, 'rel_id', 'id');
}
public function part1() {
return $this->rel()->where('lvl', 1)->inRandomOrder()->take(8);
}
public function part2() {
return $this->rel()->where('lvl', 2)->inRandomOrder()->take(2);
}
public function all_relation()
{
return $this->part1()->union($this->part2());
}
}
In the controller I try to get the results like this:
$result = MyModel::with(['all_relation' => function($query) {
$query->orderByRaw('RAND()');
}])->where('fv', '>', 0)->where('url', $url)->first();
dd($result );
I have error SQLSTATE[HY093]: Invalid parameter number.
What is this related to? I started developing on Laravel 10, now I've updated to 12 and noticed this error. I don't know if it's related to the version. I can't figure out what's wrong, the number of records in the linked table is enough.