Blade - map database values and show in view

Posted 1 month ago by oliverbusk

Hi all.

So imagine I have a database table, that has two columns: fields and operators. The fields can have below values:

fromName, from, toName

and the operators column can have:

=, !=

Now, I would like to show the above in my Blade view, but I wish to rewrite the actual values to something more readable.

I can do:

@forelse ($stream->rules as $rule)
  @if ($rule->field === 'fromName')
      From Name
  @endif


   @if ($rule->field === 'toName')
      To Name
   @endif

   @if ($rule->operator === '=')
      Equals
   @endif

   @if ($rule->field === '!=')
      Does Not Equals
   @endif

@empty

    <div>No rules defined!</div>

@endforelse

And so on - however this feel rather chunky and messy.

Is there a way to "map" the names more elegant?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.