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

softdeletes resolveRouteBinding overwrite #26

Closed
deantheiceman opened this issue Nov 20, 2020 · 2 comments
Closed

softdeletes resolveRouteBinding overwrite #26

deantheiceman opened this issue Nov 20, 2020 · 2 comments
Labels

Comments

@deantheiceman
Copy link

To use SoftDeletes we have this:

   use Illuminate\Database\Eloquent\SoftDeletes;

    public function resolveRouteBinding($value, $field = null)
    {
        return in_array(SoftDeletes::class, class_uses($this))
            ? $this->where($this->getRouteKeyName(), $value)->withTrashed()->first()
            : parent::resolveRouteBinding($value);
    }

How can I make this work with laravel-optimus?

@antonkomarev
Copy link
Member

You want to have ability to resolve soft deleted entities together with decoding?

@deantheiceman
Copy link
Author

Thanks, I think I solved it like this:

public function resolveRouteBinding($value, $field = null)
    {
        if (is_string($value) && ctype_digit($value)) {
            $value = (int) $value;
        }

        if (!is_int($value)) {
            return null;
        }

        $id = $this->getOptimus()->decode($value);

        return in_array(SoftDeletes::class, class_uses($this))
            ? $this->where($this->getRouteKeyName(), '=', $id)->withTrashed()->first()
            : parent::resolveRouteBinding($value);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants