PHP concatenation in the selection field

Asked

Viewed 66 times

-2

Follow my question regarding concatenation in PHP in the code below:

<td>{{$projeto->situacao_projeto == 'AA' ? 'Aguardando Autorização' : 'AP' ? 'Aprovado' :'CS' ? 'Cancelado Suspenso' : 'Reprovado'}}</td>

The selection field has 4 types and in the result view only displays and repeats only the "Canceled Suspended" even if selecting different types.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • 1

    Was the result the same repetition of the same type. <td> {{($project->situacao_project == 'AA') ? 'Awaiting Authorization' : ($project->situacao_project == 'AP') ? 'Approved' : ($project->situacao_project == 'CS') ? 'Cancelled Suspended' : ($project->situacao_project == 'RP') ? 'Failed' 'Awaiting Authorization'}}</td>

  • exactly as @Hugoleonardo commented, for each if must have a new condition, in case it is doing elseif then it must have a new condition.

  • However @Eduardo this ternary operator is not recommended for a complex conditional operation, that is, it is used for return and the implemented logic is something small.

  • @Hugoleonardo for sure, being more of a if I no longer work this way, would do the traditional way without a doubt.

  • @Eduardo follows the resolution of the problem. I optimized the sql query of the Controller folder of the project in question: DB::raw('(CASE WHEN projects.situacao_project = "AA" THEN "Awaiting Authorization" WHEN projects.situacao_project = "AP" THEN "Approved" WHEN projects.situacao_project = "AA" THEN "Canceled Suspended" ELSE "Failed" END) AS situacao_project'))

Show 1 more comment

1 answer

-1

Solved: I optimized the query in the Controller module of the project in question follows the resolution code below:

DB::raw('( CASE

WHEN projects.situacao_project = "AA" THEN "Awaiting Authorization"

WHEN projetos.situacao_projeto = "AP" THEN "Approved"

WHEN projects.situacao_project = "AA" THEN "Canceled Suspended"

ELSE "I FLUNKED"

END) AS situaca_projeto'))

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.