Choosing which data to post using form

Posted 3 years ago by mallorca

Hi, I'm new to laravel and I'm using v5.1.

I noticed that authcontroller has something like this:

    protected function create(array $data)
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'company_id' => $data['club_id'],
            'password' => bcrypt($data['password']),

Right now I have the following in my ArticlesController:

$article = new Article($request->all());
return redirect('/');

It's setting the forreign key user_id to the article, based on what the logged in user's id is. However, if I don't want the controller to request all the data, but instead if I want to declare which fields should set which data, how can I do that on my own?

I would like to be able to set the articles club_id to the same value as the users club_id value. What would be a good practice to achieve this? I would appreciate if a experienced artisan can guide me in the right path and perhaps provide some code examples. Thanks!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.