-
-
Notifications
You must be signed in to change notification settings - Fork 138
Description
Environment
- Laravel Version: 11.46.1 (issue appears in Laravel 11.x)
- PHP Version: 8.4.13
- Compoships Version: 2.5.1
- Database: MySQL/MariaDB with table prefix pa_
After upgrading from Laravel 9 to Laravel 11, we encountered an issue where database table prefixes were not being applied when using the Compoships trait. This caused all queries to fail with "table not found" errors, even though the tables existed with the correct prefix.
The Problem
In Laravel 11, when a model uses the Compoships trait, the newBaseQueryBuilder() method creates a new Grammar instance but the table prefix is not applied to the Grammar object.
Error Message
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database.structures' doesn't exist
The query was looking for structures instead of pa_structures (with the configured prefix).
Root Cause
I think the issue is in the Compoships trait, in the newBaseQueryBuilder() method at line 77:
// vendor/awobaz/compoships/src/Compoships.php:77
if (method_exists($grammar, 'withTablePrefix')) {
$grammar = $connection->withTablePrefix($grammar);
}
The bug: The condition checks if $grammar has the method withTablePrefix, but Grammar objects don't have this method - it exists on the Connection object instead.
This means the condition always evaluates to false, and the withTablePrefix() method is never called, leaving the Grammar without a prefix.