2

I really like the idea of Route Model Binding.

Is there a similar way to cast parameters (which are Strings) to Intergers?

The reason is that I often have the parameters year and month, but I would like to have it as an Integer, because the database seems to handle String and Integers in different ways.

Sören Henning
  • 326
  • 4
  • 16

2 Answers2

4

Update using PHP7, if anyone else comes looking:

public function view(int $id)
{
  echo gettype($id);
  // Outputs "integer"
}
Ixalmida
  • 603
  • 5
  • 15
2

Yes there is. You can use Route Binding similar to what I answered here. It's unfortunate that it exists but is not documented in the Laravel docs.

Community
  • 1
  • 1