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');
}
Hi John,
In you can access the current authenticated user using:
Auth()->User()
So for this example you could use
Auth()->User()->id
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community