Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind Enum to routes static parameter

How do I bind a enum from my Model to a static parameter in my routes definition?

Example (made up):

Model:

class User (..)
{
    public static enum TYPES { Default, Admin, Editor, Visitor }
}

Controller:

class Users (..)
{
    public static void create(long parentUserId, User.TYPES type)
    {
       (..)
    }
}

Routes:

GET     /user/{parentUserId}/create/editor  Users.create(type:User.TYPES.Editor)

View template:

<a href="@{Users.create(user.id, 'Editor')}">create editor</a>

or

<a href="@{Users.create(user.id, User.TYPES.Editor)}">create editor</a>

Both don't work. How should I set this up?

like image 628
Robert de W Avatar asked Nov 13 '22 19:11

Robert de W


1 Answers

EDIT: I've tested this with working environment.

The following works:

Template:

  <a href="@{Application.create(5, models.Game.GameType.Succession.name())}">create editor</a>

Route:

 GET     /user/{parentUserId}/create/{type}/editor  Application.create  

Controller:

  public static void create(long parentUserId, Game.GameType type)
    { ... }

The route with a predefined parameter doesn't work:

GET     /user/{parentUserId}/editor  Application.create(type:models.Game.GameType.Succession.name())

It will always set type to null

like image 154
Pere Villega Avatar answered Nov 16 '22 21:11

Pere Villega