Closed vishaltomar76 closed 3 years ago
Hi @vishaltomar76, what library do you use for MongoDB? According to the Laravel first
method definition, it shouldn't return an array:
/**
* Execute the query and get the first result.
*
* @param array|string $columns
* @return \Illuminate\Database\Eloquent\Model|object|static|null
*/
public function first($columns = ['*'])
{
return $this->take(1)->get($columns)->first();
}
Hello @babenkoivan I am using the below library for MongoDB https://github.com/jenssegers/laravel-mongodb
Everywhere I used the first() method it returning the object... but only the above case it returning array don't know why...
Hey @vishaltomar76, I'll need your help with this. Can you maybe share what exactly $record
contains? If it's an array, then please open an issue in https://github.com/jenssegers/laravel-mongodb, because it violates Laravel's first
method definition.
Hey @vishaltomar76, I'll need your help with this. Can you maybe share what exactly
$record
contains? If it's an array, then please open an issue in https://github.com/jenssegers/laravel-mongodb, because it violates Laravel'sfirst
method definition.
Yes, $record contains an array. If i am applying Model query with first method then it always return object but if I use the DB Query builder then it returning array. Why you are using DB query? You can also replace it by Model query then it will work fine
Hey @vishaltomar76, please open an issue in the https://github.com/jenssegers/laravel-mongodb repository. I'm pretty sure it uses the BuildsQueries
trait and doesn't respect the definition of the first
method:
/**
* Execute the query and get the first result.
*
* @param array|string $columns
* @return \Illuminate\Database\Eloquent\Model|object|static|null
*/
public function first($columns = ['*'])
{
return $this->take(1)->get($columns)->first();
}
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days
I have 2 existing indexes in elastic search and i have written another migration for 3rd index then it give me the below error when i am trying to run the "php artisan elastic:migrate"
Trying to get property 'batch' of non-object in Repositories\MigrationRepository.php:53 When i try to debug it the i found..... $record = $this->table() ->select('batch') ->orderBy('batch', 'desc') ->first(); return isset($record) ? (int)$record->batch : null;