Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.