🛠 Configuration
Here is the default configuration for Laravel Like package. You can customize the configuration as per your requirements.
Configuration file
Path: config/like.php
return [
'name' => 'The interactions configuration',
/*
* The flag to determine if the interactions table should use UUIDs.
* If you want to use UUIDs instead of auto-incrementing integers for your interactions table, set this to true.
*/
'is_uuids' => false,
/*
* The table name for interaction records.
*/
'table_name' => 'likes',
/*
* The model class for the interaction table.
*/
'interaction_model' => 'CSlant\LaravelLike\Models\Like',
/*
* The model and foreign key for the user relationship.
*/
'users' => [
/*
* User model class.
* Use this to set the user model class for the user relationship.
*/
'model' => 'App\Models\User',
/*
* User tables foreign key name.
* Use this to set the foreign key name for the user relationship.
*/
'foreign_key' => 'user_id',
],
];
If you want to change the configuration, you can publish the configuration file in the installation step.
And if you have already run the migration, you need rollback the migration and run it again to apply the changes.
php artisan migrate:rollback
If you have rolled back the migration, please handle follow to the modification instructions below to customize it to suit your project.
Change the table name
You can change the table name for interaction records by updating the table_name key in the configuration file.
'table_name' => 'interactions',
So now, the interactions table will be named interactions.
Use UUIDs for interactions
If you want to use UUIDs instead of auto-incrementing integers for your interactions table, set the is_uuids key to true.
'is_uuids' => true,
Change the user model
Sometimes, you may want to use a different user model for the interactions.
Maybe you are using a modular structure, or using another pattern like DDD(Domain-Driven Design). That's why you can change the user model class in the configuration file. You can skip this step if you are using the default Laravel user model.
Now, update the model key in the users array to set the user model class.
'user' => [
'model' => \App\Modules\User\CustomUser::class, // Custom the user model class
],
\App\Modules\User\CustomUser::classis the custom user model class.- You can replace
CustomUserwith your custom user model class.
Change the foreign key
If you are using a different foreign key for the user relationship, you can update the foreign_key key in the users array.
'user' => [
'foreign_key' => 'customer_id', // Custom foreign key name for the user relationship
],
customer_idis the custom foreign key name for the user relationship.
Re-run the migration
After you have made the changes to the configuration file, you need to re-run the migration to apply the changes.
php artisan migrate
That's it! You have successfully configured the Laravel Like package. 🎉