GabrielVa
GabrielVa

Reputation: 2388

Laravel Changing number to Text

Working on a Laravel 4.2 app here, I have a SQL value in which it returns a 0 or 1 value. I would like to cast this as a Yes/No field, how would I do this in my coding? On the Controller side of things I assume?

Blade PHP:

  <td>{{  $value->allow_na  }}</td>

Controller:

$value->allow_na = Input::get('allow_na');

enter image description here

Upvotes: 0

Views: 661

Answers (3)

Md. Noor-A-Alam Siddique
Md. Noor-A-Alam Siddique

Reputation: 1077

Blade PHP:

<td>{{  $value->allow_na  }}</td>

Controller:

if ( Input::get('allow_na') == 0 )
   { 
       $value->allow_na = "No";
   }
else
   { 
       $value->allow_na = "Yes";
   }

Upvotes: 0

Landjea
Landjea

Reputation: 384

Another option, on your model you can add a mutator to convert that for you every time.

public function setAllowNAAttribute($value)
{
    $this->attributes['allow_na'] = ($value) ? 'Yes' : 'No';
}

Link : https://laravel.com/docs/4.2/eloquent#accessors-and-mutators

Upvotes: 0

Nabin Kunwar
Nabin Kunwar

Reputation: 1996

On Blade you can do

<td>{{  ($value->allow_na)?'Yes':'No'  }}</td>

Or Same way on controller

$value->allow_na = (Input::get('allow_na'))?'Yes':'No';

Upvotes: 1

Related Questions