Answer the question
In order to leave comments, you need to log in
How to properly optimize running code (here, the code is small) in Laravel?
Hello.
In my Profile project, this is a model separate from the User. And it actively interacts with other entities (in fact, the User is just for authentication and authorization, and everything else is on the Profile).
At this stage, I write the following code in the controllers:
private function getProfile()
{
$auth_id = Auth::id(); //id текущего пользователя
$user = User::find($auth_id); //получаем объект текущего пользователя
$profile = Profile::firstOrNew(['user_id' => $auth_id]); //ищем или создаем кастомера для текущего пользователя
$user->profiles()->save($profile); // сохраняем его в базе вместе с отношением к текущему юзеру
return $profile;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question