danielveselinov / BrainsterProjects_DanielVeselinovWD6

All my projects that I've been working on while taking Brainster Full Stack Web Academy.
0 stars 0 forks source link

Creating project #2

Open krekas opened 1 year ago

krekas commented 1 year ago

You have projects relation in your user model. So in store() method here https://github.com/danielveselinov/BrainsterProjects_DanielVeselinovWD6/blob/project03/app/Http/Controllers/ProjectController.php#L45 you can write:

$project = Auth::user()->projects()->create([
    'name' => $request->name,
    'description' => $request->description
]);

Link to docs https://laravel.com/docs/10.x/eloquent-relationships#the-create-method

danielveselinov commented 1 year ago

Thank you, appreciate the feedback. I have following question about that.

$project = Auth::user()->projects()->update([
    'name' => $request->name,
    'description' => $request->description
]);

This line of code will update the project for authorised user, right?

krekas commented 1 year ago

Yes, you are corrent. For the current authenticated user