vendredi 17 février 2017

Change element style according to database flag

I have a table with a couple of flags:

Foo : Migration

Schema::create('foo', function(Blueprint $table)
   {
      $table->increments('id')->unsigned();                            
      $table->string('field_1', 10);
      $table->string('field_2', 10);
      $table->boolean('flag_1')->default(0);
      $table->boolean('flag_2')->default(0);
      $table->boolean('flag_3')->default(0);
      $table->timestamps();
    });  

I have a kind of complex query that I could not achieve using laravel's relationships, (BelongsTo, BelongsToMany, etc...). So I did it like so:

public function myFunc($filterOne, $filterTwo)
   {
      SELECT
      table1.id, table1.name,
      table2.id, table2.week_day,            
      table3.id,
      table4.date
      FROM table1
      LEFT JOIN table2 ON table2.id = table1.table2_id
      LEFT JOIN table3 ON table2.table3_id = table3.id
      LEFT JOIN table4 ON table3.id = table4.table3_id
      WHERE table1.cod_field='.$filterOne.' AND table3.date = "'.$filterTwo . '"
   }  

What I need is:
Everytime one of those flags are true, I need to call user's attention by changing the icon's color (that's what I found be the best way to do it).

As I'm using QueryBuilder instead of Eloquent so I can not use Laravel's Accessors.

Here is my HTML with the icons in place:

@foreach($obj->myFunc($obj->field1, $obj->field2) AS $disc)
   <i class=" flag fa fa-check fa-lg"></i>
   <i class=" flag fa fa-camera-retro fa-lg"></i>
@endforeach

Instead of writing the flag's value (0 / 1) I want to write a CSS class.
That way I could change it's color to call user's attention. But How ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lqeSdW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire