-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.
It is possible to use the ternary operator under several conditions simultaneously?
– rray
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>
– Hugo Leonardo
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.
– Eduardo
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.
– Hugo Leonardo
@Hugoleonardo for sure, being more of a if I no longer work this way, would do the traditional way without a doubt.
– Eduardo
@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'))
– Hugo Leonardo