1

i want to create if else from database record.

for example : i've record "1" in "status" row.

"if status = "1" 
echo Show Button
else 
don't show button"

what code in controller and view?

2 Answers 2

1

Just put in the view your if

 @foreach ($itens as $item)
    @if ($item->status == 1) 
    <input type="button"/>
    @endif
@endforeach

In your controller you don't need to care about it

Sign up to request clarification or add additional context in comments.

2 Comments

thanks! i changed @if ($item->status) and it's worked i don't know why lol xD
is because 1 == true. if your status is boolean it's ok, but if it is a integer see to another values... 2, 3... is what you whant
0

You can use Laravel Blade Template Control Structures for this

i.e.

@if($status == 1)
...
<!-- HTML Code to generate button -->
...
@endif

Read more here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.