InfyOmLabs / laravel-generator

API and Admin Panel CRUD Generator for Laravel.
https://www.infyom.com/open-source
MIT License
3.79k stars 814 forks source link

Created By field using id of logged in user #797

Closed rajkumarpb closed 2 years ago

rajkumarpb commented 4 years ago

As mentioned in title, I would like to add the id of logged in user to be added in created_by field in table for every insert and in modified_by field if edit. How can I achieve this with infyom generator? Sorry if it's very basic question but I'm a noob in Laravel.

tolu-six commented 4 years ago

Hi rajkumarpb, You can get the logged in user id, by using the auth middleware, which you then map with the created_by or modified_by and finally save

ajayinfyom commented 4 years ago

@rajkumarpb currently, there is no way to do this, will add support for it.

mitulgolakiya commented 2 years ago

We do not plan to do that as a part of this package. There are several other ways that can be accomplished if needed. Best way will be,

You publish the templates and then modify the template the way you need. I think best way will be,

  1. Modify migration stub to add created_by and updated_by field
  2. Create one common trait which listens for model creating and updating events and then updates the fields accordingly. so update the model stub file

And other files that seem to be updated. We will try to write some tutorials on this and attach the link here.