ARCANEDEV / LaravelSettings

:open_file_folder: This package allows you to persists configs/settings for Laravel projects.
MIT License
75 stars 16 forks source link

set foreign key for user_id #18

Closed Themesfa closed 6 years ago

Themesfa commented 6 years ago

I set a foreign key for user_id references id on users with this code in migration file:

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');

i want to delete user settings when user deleted. but there is a problem with default settings that users_id is 0 . because user_id 0 is not exists in users table and it just a default value for normal settings and i get error when i want to set a normal setting . how i can fix that ? should i use a second table for normal settings and how i do that ?

arcanedev-maroc commented 6 years ago

You can solve your problem by using the Model's event: https://laravel.com/docs/5.6/eloquent#events

Themesfa commented 6 years ago

you mean i must remove user settings by create a listener and fire an event on delete a user to remove all setting related to it ?

arcanedev-maroc commented 6 years ago

Yes, something like this listener handled when deleting a user.