Support the ongoing development of Laravel.io →
Input Database Blade
Last updated 2 years ago.
0

Is it possible to use switch/case or if/else in blade?

if $player->foot ="l" then $foot = "left";

Last updated 2 years ago.
0

If you don't the var set in the template and just want to display the other value,

<div>
@if ($player->foot == "l")
    Left
@elseif ($player->foot == "r")
    Right
@else
    Both
@endif
</div>

Blade template reference http://laravel.com/docs/4.2/templates

Or you could check the data before and pass a display var to the view, of course that is depending on how you pass the data in.

Last updated 2 years ago.
0

Thanks.

Is it possible to change the data in the select in the database? (CASE)

Last updated 2 years ago.
0

I assume you have enum field (l, r, b), so you can use accessor like below:

// Player model (or whatever your model is ofc)
public function getFootAttribute($value)
{
  switch ($value)
  {
    case 'b':
      return 'Both';
    case 'l':
      return 'Left';
    default:
      return 'Right';
  }
}

// then
$player->foot; // returns Right / Left / Both
Last updated 2 years ago.
0

This is the solution. I don't know why, but it works.

Many thanks.

regards markus

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.