kriszpchicken
4 months ago

Only display data in views if it exists

Posted 4 months ago by kriszpchicken

I am working on a to-do application. A data has a created_by and an updated_by attribute, but naturally if I want to display the updated_by attribute in my index, I get an error message. So I would like to make it so, that if the updated_by doesn't exist, the index page just doesn't display it, if it exists, it will be displayed. I think it should be resolved with an if/else statement, but I am not really sure how to do that.

index.blade.php

 @foreach($tasks as $task)
            <tr>
                <td>{{$task->id}}</td>
                <td>{{$task->title}}</td>
                <td>{{$task->description}}</td>
                <td>{{$task->created_at}}</td>
                <td>{{$task->createdBy->name}}</td>
                <td>{{$task->updatedBy->name}}</td>

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