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

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();
$model->setConnection('connection_name');
$result = $model->where($this->model->getKeyName(),'=',1)->get()->last();
Last updated 9 years ago.
0

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

$model->newQuery()->find(1);
0

L 5.6 Thank you @mfrancois and @jarektkaczyk !

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

catalisio catalisio Joined 8 Jan 2015

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.