Support the ongoing development of →
Database Eloquent
Last updated 2 years ago.

Hi catalisio,

It's because the find method create a new instance of query.

	public static function find($id, $columns = array('*'))
		if (is_array($id) && empty($id)) return new Collection;

		$instance = new static;

		return $instance->newQuery()->find($id, $columns);

That why don't use find and use a query like:

$model = new EloquentModel();
$result = $model->where($this->model->getKeyName(),'=',1)->get()->last();
Last updated 9 years ago.

@mfrancois You're correct. However, this is the way to query on the instantiated model:


L 5.6 Thank you @mfrancois and @jarektkaczyk !

Last updated 5 years ago.

Sign in to participate in this thread!


Your banner here too?

catalisio catalisio Joined 8 Jan 2015


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.