Coder Social home page Coder Social logo

laravel-model-hashid's Issues

Breaking Change in 2.4.0

When upgrading to version 2.4.0 my routes stopped working. I am using route model binding with ModelA and I have the following routes in web.php

Route::get('/permanent/modelA/{modelA}', function ($modelA) {
        $modelA = ModelA::findByHashId($modelA);

        if ($modelA) {
            return redirect(route('modelA.show', ['modelA' => $modelA]));
        }

        abort(404);
    })->name('modelA.permalink');

    Route::get('/modelA/{modelA:slug}', [ModelAController::class, 'show'])->name('modelA.show');

The idea being that the slug might change but I would always be able to use the hash id to find the model. This behavior no longer works with version 2.4.0. The easiest work around is to use explicit model binding.

Undefined array key 0 when hash id doesn't exist

When trying to find a model using a hash id that doesn't exist, this exception is thrown:

Undefined array key 0

image

The function that is called can return the following values:

@return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static[]|static|null

Which is then accessed:

return $generator->decode($hashIdInstance->hashIdForKey)[0];

When a model can't be found, I suggest a null being returned instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.