ristlin
242
6
Laravel

setting getRouteKeyName if a condition is met

Posted 2 months ago by ristlin

So I'd only like to set my own route key name if the column is not null (i.e., the user has explicitly set their URL name). I've tried the following, but I can't seem to get it to work. Basically, the conditionals are ignored.

  public function getRouteKeyName()
    {
    // if the user has set a url name, set it as the key name
        if ('link_name' != null) {
            return 'link_name';
        }
    // otherwise, return default
    return 'id';
    }

Any suggestions?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.