Skip to content

Instantly share code, notes, and snippets.

@DeeSouza
Last active January 2, 2019 10:59
Show Gist options
  • Save DeeSouza/d811f8890d96b78ae47404e5054c4e6b to your computer and use it in GitHub Desktop.
Save DeeSouza/d811f8890d96b78ae47404e5054c4e6b to your computer and use it in GitHub Desktop.
Get One Row in Model - Eloquent Laravel
<?php
/* Usando o método find() */
class ExampleController extends Controller{
// Dois caminhos para pegar um registro na tabela e retornar em um objeto.
// 😕 Você pode fazer assim, mas não é o "jeito" Laravel de se fazer.
$model = Author::where('id', '=', 1)->first();
// 😆😆😆 É melhor assim. Ele faz a cláusula where internamente para você.
$model = Author::find(1);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment