feat: add HasCompositePrimaryKey trait for composite primary key support
- Introduced a new trait `HasCompositePrimaryKey` to enable Eloquent models to handle composite primary keys, which are not supported natively by Eloquent. The trait requires models to implement a method to define the composite key columns and manages key retrieval for save and select queries. chore: add GrumPHP configuration for pre-commit checks - Added a `grumphp.yml` configuration file to enforce code style and static analysis checks before commits. This setup includes Laravel Pint for code style and Larastan for static analysis, ensuring code quality and consistency. chore: create PHPStan configuration file - Created a `phpstan.neon` file to configure PHPStan with Larastan for static analysis. The configuration specifies the paths to analyze and sets the analysis level to 5 for a balance between catching bugs and avoiding excessive strictness.
This commit is contained in:
@@ -2,17 +2,33 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\HasCompositePrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Utilisateur_Progression extends Model
|
||||
{
|
||||
use HasCompositePrimaryKey;
|
||||
|
||||
protected $table = 'utilisateur_progressions';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $primaryKey = ['ID_Utilisateur', 'ID_Ressource'];
|
||||
// Clé primaire composite (ID_Utilisateur + ID_Ressource), gérée par le
|
||||
// trait via compositeKeyColumns(). Eloquent impose une chaîne pour
|
||||
// $primaryKey : on y met la 1re colonne pour rester conforme au contrat.
|
||||
protected $primaryKey = 'ID_Utilisateur';
|
||||
|
||||
/**
|
||||
* Colonnes composant la clé primaire composite.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
protected function compositeKeyColumns(): array
|
||||
{
|
||||
return ['ID_Utilisateur', 'ID_Ressource'];
|
||||
}
|
||||
|
||||
protected $fillable = [
|
||||
'ID_Utilisateur',
|
||||
|
||||
Reference in New Issue
Block a user