What is the difference between Eloquent Model::get() and Eloquent Model::all()?

Asked

Viewed 66 times

1

  • What’s the difference in using Model::get() and Model::all()?
  • Some of them are more recommended to bring all the bank records?

1 answer

1


Everything is get(), that is, the method all() of Model flame get(), code that exemplifies the statement:

public static function all($columns = ['*'])
{
    $columns = is_array($columns) ? $columns : func_get_args();

    $instance = new static;

    return $instance->newQuery()->get($columns);
}

another point to say is that the returns brought are produced by Builder (Illuminate\Database\Eloquent\Builder) which is the class responsible for constructing expressions to results with filters, ordination, paging, selection of fields from a table, etc.. On that line of code $instance->newQuery()->get($columns); the newQuery() produces a Builder.

In earlier versions it didn’t work that way, it had a small difference where get does not work in the model, only all, but, the return who did Builder with the method get and there was a unification to facilitate the handling of these operations that produces the same result.

Another point when one leaves for expression construction the method is the get the all does not exist because as already said the method all is part of the Model.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.