alamizo alamizo - 1 year ago 97
PHP Question

Laravel trying to get user id to store into posts table

public function store(Request $request)
$this->validate($request, array(
'title' => 'required|max:255|min:2',
'slug' => 'required|alpha_dash|unique:articles,slug',
'category_id' => 'required|integer',
'content' => 'required|min:2'

$article = new Article;
$article->title = $request->title;
$article->slug = $request->slug;
$article->category_id = $request->category_id;

$article->content = $request->content;

Session::flash('success', 'Your article has been published.');
return redirect()->route('', $article->id);

There is a user_id column on the articles table,

This is my store function but when I create the post I am looking for a way to store the logged in user id to the user_id column in the articles table.

Answer Source

Get the authed user.

$article->user_id = Auth::user()->id;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download