Skip to content

Instantly share code, notes, and snippets.

@flyingluscas
Last active July 26, 2016 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyingluscas/8f5dccc67d4d0317e20d93124343d769 to your computer and use it in GitHub Desktop.
Save flyingluscas/8f5dccc67d4d0317e20d93124343d769 to your computer and use it in GitHub Desktop.
Laravel Model Save Method

Criando post e salvando no banco

  $post = new Post([
    'title' => 'Batatas não avoam',
    'author' => 'Lucas Pires',
  ]);
  
  $post->save();

Atualizando titulo do Post

  $post = Post::find($id);
  
  $post->title = 'Novo titulo';
  
  $post->save();

Atualizando várias informações ao mesmo tempo

  $post = Post::find($id);
  
  $post->fill($request->all());
  
  $post->save();

ou

  Post::find($id)->fill($request->except('_token'))->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment