-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does laravel-mongodb respect $hidden? #1119
Comments
I'm seeing this same issue. I'm seeing the fields listed as hidden in the object, but they aren't being removed from the actual data array. |
@jenssegers still not fixed? |
@rohitsodhia @coreywelch is this still the case? I cannot reproduce it with the following test Test implementation<?php
declare(strict_types=1);
namespace MongoDB\Laravel\Tests\Eloquent;
use MongoDB\Laravel\Eloquent\Model as Eloquent;
use MongoDB\Laravel\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;
final class PropertyTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Animal::truncate();
EatableAnimal::truncate();
}
#[Test]
public function can_hide_certain_properties(): void
{
Animal::insert([
['name' => 'Lion', 'country' => 'Africa', 'can_be_eaten' => false],
]);
EatableAnimal::insert([
['name' => 'Cow', 'country' => 'Europe', 'can_be_eaten' => true],
]);
[$lion] = Animal::all()->toArray();
[$cow] = EatableAnimal::all()->toArray();
self::assertArrayHasKey('country', $lion);
self::assertArrayNotHasKey('country', $cow);
}
}
/**
* @property string $name
* @property string $country
* @property bool $can_be_eaten
*/
class Animal extends Eloquent
{
}
/**
* @property string $name
* @property string $country
* @property bool $can_be_eaten
*/
class EatableAnimal extends Eloquent
{
protected $hidden = ['country'];
} |
Hi @Treggats, to close this, please open a PR and add your tests to cover this problem. much thanks. |
👌 will do |
@hans-thomas I've opened #2687 for this. |
Thank you @Treggats |
I'm having trouble figuring this out in the code, and I'm not sure if maybe I'm doing it wrong, but I have fields I'd like to add to a model that I don't want saved into the final document. Eloquent usually uses $hidden for this kind of stuff, but it doesn't seem to work here. Am I missing something?
The text was updated successfully, but these errors were encountered: