Last active
January 2, 2019 10:59
-
-
Save DeeSouza/d811f8890d96b78ae47404e5054c4e6b to your computer and use it in GitHub Desktop.
Get One Row in Model - Eloquent Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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