Skip to content
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

withTrashed() not working properly on show and edit #4963

Closed
elnur-ibr opened this issue Jun 1, 2020 · 2 comments · Fixed by #5195
Closed

withTrashed() not working properly on show and edit #4963

elnur-ibr opened this issue Jun 1, 2020 · 2 comments · Fixed by #5195
Assignees

Comments

@elnur-ibr
Copy link

Version information

  • Laravel: v7.12.0
  • Voyager: v1.4.1
  • PHP: 7.2.19

Description

Softdelete does not work properly in both methods "show" and "edit" of "TCG\Voyager\Http\Controllers\VoyagerBaseController". And interrupts adding scope to model.

....
// Use withTrashed() if model uses SoftDeletes and if toggle is selected
if ($model && in_array(SoftDeletes::class, class_uses_recursive($model))) {
    $model = $model->withTrashed();
}
if ($dataType->scope && $dataType->scope != '' && method_exists($model, 'scope'.ucfirst($dataType->scope))) {
    $model = $model->{$dataType->scope}();
}
...

$model = $model->withTrashed(); returns instance of "Illuminate\Database\Eloquent\Builder" instead of Model instance. As follows method_exists($model, 'scope'.ucfirst($dataType->scope) returns false. It should be as follows.

....
// Use withTrashed() if model uses SoftDeletes and if toggle is selected
if ($model && in_array(SoftDeletes::class, class_uses_recursive($model))) {
    $model->withTrashed();
}
if ($dataType->scope && $dataType->scope != '' && method_exists($model, 'scope'.ucfirst($dataType->scope))) {
    $model->{$dataType->scope}();
}
...
@MrCrayon
Copy link
Collaborator

@elnur-ibr Thanks for reporting it, I hope my PR fixes it also in all the other methods.

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants