jeudi 25 août 2016

Laravel 5 - Inserting all POST data into database?

I'm using Laravel 5 and I created a resource controller, setup routing and setup my database model.

My question is: when I do a POST, my store method is called on the controller but how can I take the request data and insert a new entry in the db without having to explicitly set every field?

Here's my code:

public function store(Request $request)
{
  $data = $request->all(); // this grabs all my request data - great!
  $user = new User;
  $user-> ??? // insert ALL posted data
  $user->save();
}

I understand that I can do...

$user->name = $request->name;

...for every field. But can someone tell me how to insert everything?

I realize I can probably do a foreach but I'm wondering if there's something better.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire