The above example will make a single database query, retrieve all the records from the table, and hydrate Eloquent models one by one. This approach will make only one database query to retrieve all the posts. But usesphp generatorto optimize the memory usage. when can you use this? Though...
phpnamespaceIlluminate\Database\Query;useClosure;useIlluminate\Support\Collection;useIlluminate\Database\ConnectionInterface;useIlluminate\Database\Query\Grammars\Grammar;useIlluminate\Database\Query\Processors\Processor;classBuilder{//methods and variables come here} 如您所见,Eloquent 模型使用一些类,如Database...
If you pass an object or collection of objects, the mailer will automatically use their email and name properties when determining the email's recipients, so make sure these attributes are available on your objects. Once you have specified your recipients, you may pass an instance of your mail...
This allows you to easily perform further validation and even add more error messages to the message collection. To get started, call the after method on a validator instance:1$validator = Validator::make(/* ... */); 2 3$validator->after(function ($validator) { 4 if ($this->...
Of course, in addition to retrieving all of the records for a given table, you may also retrieve single records using find or first. Instead of returning a collection of models, these methods return a single model instance: 通过find或first方法来检索单条记录 ...
// returns a collection of first names $collection = App\Person::all()->where('type', 'engineer')->lists('first_name'); // returns all the meta records for user 1 $collection = App\WP_Meta::whereUserId(1)->get(); // returns the first & last name meta values ...
注意在这里我们使用了laravel5提供的route model binding特性,我们在控制器中使用Task类typehinting了task参数,而该task参数,而该task参数和routes.php中定义的wildcast路由Route::get('tasks/{task}','xxx'}定义的task相匹配,因此laravel在调用我们的控制器时自动注入Task模型(以id为索引)。这个功能后续再做进一步的...
I commonly find that there is no shorthand way of sorting collections by multiple fields. A large amount of extra code is required just by adding in an extra field. What I really want to do is this: $collection->sortBy(['Surname', 'Foren...
$collection->index('name'); $collection->unique('email'); }); 示例 基本使用 查出所有user $users = User::all(); 按主键检索记录 $user = User::find('517c43667db388101e00000f'); where操作查询 $users = User::where('votes', '>', 100)->take(10)->get(); ...
Route::get('/cache', function () { return Cache::get('key'); // === return cache('key'); }); public function testBasicExample() { Cache::shouldReceive('get') ->with('key') ->andReturn('value'); $this->visit('/cache') ->see('value'); } ...