Support the ongoing development of Laravel.io →
Authentication Input Forms

Hi,

I have a form and would like to get the user_id out when submitted here is my store function:

public function store(Artwork2Request $request)
    {
        //
        $this->validate($request,[
            'title'=>'required|min:3',
            'size' => 'required',
//            'photo_id' => 'required|mimes:jpeg,jpg,gif,png',
            'artistsnotes' => 'required|min:3',
//            'photo'=>'required|mimes:jpeg,jpg,png,gif'
        ]);
        $input = $request->all();

        $input['user_id'] = $request->user()->id;

        if($file = $request->file('photo_id')){
            $name = time().$file->getClientOriginalName();
            $file->move('images/gallery2', $name);
            $photo = Photo::create(['file'=>$name]);
            $input['photo_id'] = $photo->id;
            $input['slug'] = str_slug($input['title']);
            $request->user()->id;
        }

        Artwork2::create($input);

        return redirect('/admin/artwork/create');
    }
Last updated 3 years ago.
0

Hi John,

In you can access the current authenticated user using:

Auth()->User()

So for this example you could use

Auth()->User()->id
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.