-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
Laravel paginated collection resource issue #444
Comments
"fixed it" by adding the attribute public $resource; to the models. |
I have the same issue, i opened a ticket to laravel laravel/framework#35791 I added the public $resource attribute to the models, but still is not working for me. [UPDATE] i fixed it by doing this:
Awful fix... but at least it's working |
Same problem. I just using QueryBuilder as class BarCollectionSearchResource extends ResourceCollection
{
protected YandexSearchDTO $dto;
public function __construct(YandexSearchDTO $dto)
{
$this->dto = $dto;
parent::__construct($this->getResource());
}
public function toArray($request)
{
return $this->resource->map(function(stdClass $bar) {
$bar = (array) $bar;
return [
'url' => \Base_Url::toBarCard($bar),
'name' => $this->setHighlight($bar['name']),
'address' => $this->setHighlight($bar['address']),
'vip' => \Bar_Service_Tariff::isActive($bar['id']),
//etc transformations
];
});
}
protected function getResource(): AbstractPaginator
{
$builder = DB::table('bar_struct as s')
//some of joins
->select() //some of selects
->where() //some of where
->groupBy('s.id');
return $builder->paginate($this->dto->perPage, ['*'], 'page', $this->dto->page);
}
protected function setHighlight(string $where = null):? string
{
return preg_replace('~(' . $this->dto->query . ')~iu', "<em>$1</em>", $where);
}
} But got error class YandexSearchController extends Controller
{
public function indexAction(Request $request)
{
return new BarCollectionSearchResource(
new YandexSearchDTO($request)
);
}
} https://skr.sh/sILFeRgmw0y P.S. |
I do have a new behavior without any app code changes. Before update to L6.18 (don't know the exact version before) it worked as exspected. Then I did upgrade to L7 to get the latest laraveldoctrine adaptions. But I also got the same behaviour.
Context:
I create a paginated Result from Doctrine via:
In modelcollection I do the normal to_Array stuff to 'select' the fields, as in:
This worked the past years, but not anymore. I am pretty clueless - just outcommenting the line in vendor is not my prefered solution ;).
Package version, Laravel version
latest laraveldoctrine package, Laravel 6.18+
Expected behaviour
Returning a JSON resource
Actual behaviour
message: Undefined property: App\Models<model>::$resource
Steps to reproduce the behaviour
I can return to the old, successful behavior if I uncomment line ~29 in vendor/laravel/framework/src/Illuminate/Http/Resources/Json/PaginatedResourceResponse.php
The text was updated successfully, but these errors were encountered: