'laravel livewire exception: Queueing collections with multiple model connections is not supported
I´m beggining my Livewire journey and have created a list component which contains a form component for each of the list elements, and as I am trying to make it all work I keep getting the following never before seen exception:
LogicException Queueing collections with multiple model connections is not supported.
I use the same single connection for every model in my project, and I am not queueing anything on purpose in any of the components I'm currently working, so I have no clue as to where to start debugging this exception. The error message doesn´t help much either. In fact, I don´t even know what to post here for you guys to help me, short of posting the whole project... I guess I´m just angling for any clue as to where to start looking to get this fixed, so any help is much appreciated.
Here's the error message Stack trace:
C:\Users\bfcba\OneDrive\aplicaciones\duki\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Collection.php:705
public function getQueueableConnection()
{
if ($this->isEmpty()) {
return;
}
$connection = $this->first()->getConnectionName();
$this->each(function ($model) use ($connection) {
if ($model->getConnectionName() !== $connection) {
throw new LogicException('Queueing collections with multiple model connections is not supported.');
}
});
return $connection;
}
I´ll be happy to post all the information that you consider necessary. Just let me know.
Thanks in advance.
Solution 1:[1]
You can solve this by setup the connection in your model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ModelName extends Model
{
protected $connection = "mysql";
}
Solution 2:[2]
You can also convert it to a standard collection:
$this->members = new Collection($club->members);
$this->members->push(Member::make());
Solution 3:[3]
Set the connection name in the Model:
class ModelName extends Model
{
protected $connection = "mysql";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Maher El Gamil |
Solution 2 | Sebastian Sulinski |
Solution 3 | Lu32 |