I have a hard time to acquire proper relation betwen fair_lead and product(corcel), nova try to search for pivot table in wordpress database instead of laravel database.
Laravel: 10.43.0 Nova: 4.23.0 PHP: 8.2.13 Corcel: jgrossi/corcel @ v7.0.0 -> https://github.com/corcel/corcel
My fair lead model:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class FairLead extends Model
{
public function product(): BelongsToMany
{
return $this->belongsToMany(Product::class)->using(FairLeadProduct::class)->withPivot('amount');
}
}
product model
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Corcel\WooCommerce\Model\Product as Corcel;
class Product extends Corcel
{
//use HasFactory;
protected $connection = 'corcel';
public function fair_lead(): BelongsToMany
{
return $this->belongsToMany(FairLead::class)->using(FairLeadProduct::class)->withPivot('amount');
}
}
my fair_lead_product model:
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
class FairLeadProduct extends Pivot
{
protected $connection = 'mysql';
protected $table = 'fair_lead_product'; // nova seems to ignore this
}
fields in nova Product resource:
public function fields(NovaRequest $request)
{
return [
ID::make(__('ID'), 'ID')->hideFromIndex(),
BelongsToMany::make(__('Fair Leads'), 'fair_lead', FairLead::class),
];
}
error i get:
"SQLSTATE[42S02]: Base table or view not found: 1146 Table 'WP_DATABASE_fair_lead_product' doesn't exist (Connection: corcel, SQL: select `WP_DATABASE_posts`.*,
I need to nova to search for pivot in laravel database not in corcel(wordpress) database for fair_lead_product table.
Displaying Products works well in nova, but I can't get relation work as wanted.
After few hours of digging I tried to apply solutions from: belongsToMany relationship in Laravel across multiple databases now my code looks like: FairLead.php
my product.php
Now it seems well pick databases but WP_DB_PREFIX (from corcel) seems to still apply and even twice, how to null it inside public function or bypass ?