Another way would be in the StoreProjectRequest to override prepareForValidation method public function prepareForValidation() { $this->merge(['user_id' => auth()->id]); }
I like the idea of using that creating callback to do something such as setting up additional fields or creating a related child record. I don't like the idea of utilizing auth() in there, since, like you mentioned, this could come from command line tools.
Hi, thanks for this really nice tutorial. Please let me know how do give access to admin role and also parent account of the user to create, add, delete using this method? Thank you
Hello, quick question, instead of using the model boot method is it more pertinent to use an observer to do it and gather all the project events logic in the same class ? Is it a "best practice" to use an observer ?
Yes it could be done in the observer as well. But the next few lessons in upcoming days will show why IN THIS CASE observers are not the best solutions.
@@LaravelDaily thanks, can't wait to see the rest (If i'm not buying your course before as I totally need these informations for an ongoing project ;) )
Hello, whats the difference between setting user_id automatically in creating and as a setter? I guess if someone else edit's it it would change the user as well, but just asking? :D
I have video idea for you. Create User model and relations to it for creating relationships (as in Facebook). Recently I received that task and I think it can be achieve better.
I don't really understand the problem here: you want me to show how belongsTo(User::class) relationship works? I think it's very basic, on my channel I'm trying not to cover very basic things.
@@kingstalker No. My problem: if we have table "relationships" with "user_id" and "friend_id" we can get all user friends. In example: "user_id" is User X and "friend_id" is User Y. We can create relation which get User X friends, but if we want to get User Y friends same "belongs to" not works, because they have another columns names.
Sorry I still don't understand what do you mean by "User Y friends". Can you create a demo project on Github and invite me (username PovilasKorop) and then I will try to reproduce and. help.
creating method in some companies count as anti-patterns, better use prepared trait, or set up needed properties in request class. Or use service class for creating records and in this class write logic, today you need add only user_ID, tomorrow you need to do some other calculations