Skip to content

[9.x] Fix scopes for Eloquent Relation - Exception: "TypeError" #150

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

Merged
merged 3 commits into from
Jun 25, 2022
Merged

[9.x] Fix scopes for Eloquent Relation - Exception: "TypeError" #150

merged 3 commits into from
Jun 25, 2022

Conversation

padre
Copy link
Contributor

@padre padre commented Jun 23, 2022

I have upgraded from v4 and the following instruction throws the exception "TypeError" because the input parameter of the applyScopes() function can be of type Relation and the returned value can also be of type Relation.

$returnHTML = $dataTable->with(["model" => $model])->render('backend.media.get_media_datatables', $data);

exception: "TypeError"
file: "/var/app/current/vendor/yajra/laravel-datatables-buttons/src/Services/DataTable.php"
line: 719
message: "Yajra\\DataTables\\Services\\DataTable::applyScopes(): Argument #1 ($query) must be of type Illuminate\\Database\\Eloquent\\Builder|Illuminate\\Database\\Query\\Builder, Illuminate\\Database\\Eloquent\\Relations\\MorphMany given, called in /var/app/current/vendor/yajra/laravel-datatables-buttons/src/Services/DataTable.php on line 248"
trace: [,…]
0: {file: "/var/app/current/vendor/yajra/laravel-datatables-buttons/src/Services/DataTable.php",…}
1: {file: "/var/app/current/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php",…}
2: {file: "/var/app/current/vendor/laravel/framework/src/Illuminate/Container/Util.php", line: 41,…}
3: {file: "/var/app/current/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php",…}
4: {file: "/var/app/current/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php",…}
5: {file: "/var/app/current/vendor/laravel/framework/src/Illuminate/Container/Container.php",…}
6: {file: "/var/app/current/vendor/yajra/laravel-datatables-buttons/src/Services/DataTable.php",…}
7: {file: "/var/app/current/app/Http/Controllers/Backend/MediaController.php", line: 52,…}

The input parameter of the applyScopes() function can be of type Relation and the returned value can also be of type Relation.
@yajra
Copy link
Owner

yajra commented Jun 24, 2022

Thanks for the patch and sorry for overlooking the Relation. Can you please fix phpstan and code style?

@yajra yajra changed the title Exception: "TypeError" [10.x] Fix scopes for Eloquent Relation - Exception: "TypeError" Jun 25, 2022
@yajra yajra merged commit 2631241 into yajra:master Jun 25, 2022
@yajra yajra changed the title [10.x] Fix scopes for Eloquent Relation - Exception: "TypeError" [9.x] Fix scopes for Eloquent Relation - Exception: "TypeError" Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants