Skip to content

Instantly share code, notes, and snippets.

@vinicius73
Created March 5, 2016 05:03
Show Gist options
  • Save vinicius73/76c1f69851d624bb5d74 to your computer and use it in GitHub Desktop.
Save vinicius73/76c1f69851d624bb5d74 to your computer and use it in GitHub Desktop.
Modos de uso do eloquent
<?php
// chain
// https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Model.php#L3447
// https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Model.php#L3429
$user = User::where('email', '[email protected]')->where('is_dead', false)->first();
$bastards = User::where('country', 'westeros')->whereNull('father')->get();
// https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Model.php#L574
$query = User::query();
$query->where('email', '[email protected]');
$query->where('is_dead', false);
$user = $query->first();
// https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Model.php#L1785
$query = (new User())->newQuery();
$query->where('country', 'westeros');
$query->whereNull('father');
$bastards = $query->get();
// https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Builder.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment