Blade - map database values and show in view

Posted 3 months 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

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

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

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


    <div>No rules defined!</div>


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.