0

Using Laravel and Revisionable package. I am populating a table with user record modifications and have the following code snippet:

<tr>
    <td width="150">{{ $revision->updated_at }}</td>
    <td>User</td>
    <td>{{ $revision->revisionable->first_name }} {{ $revision->revisionable->last_name }}</td>
    <td width="50">{{ $revision->fieldName() }}</td>
    <td width="50">{{ $revision->userResponsible()->first_name }}</td>
    <td>{{ $revision->oldValue() }}</td>
    <td>{{ $revision->newValue() }}</td>
</tr> 

Getting the users first and last name works fine when the original user record exists but in some cases the original record (user) is deleted and it causes an error because the user record no longer exists. Is there an IF Statement I can use to first check if the first name field returns an error? Then I can display first/last name for records that still exist and something else if it doesn't exist.

Thanks in advance!

SGlavach
  • 25
  • 2

1 Answers1

0

Blade has the orsyntax, really nice:

{{ $revision->revisionable->first_name or 'N/A'}} 
{{ $revision->revisionable->last_name or 'N/A'}}

alternatives, though not as elegant:

{{ isset($revision->revisionable->first_name) ? $revision->revisionable->first_name : 'N/A' }}

or

@if (isset($revision->revisionable->first_name))
    {{ $revision->revisionable->first_name }}
@else
    N/A
@endif
meda
  • 45,103
  • 14
  • 92
  • 122
  • 1
    Worked Great! Thanks so much, this community rocks! – SGlavach Jan 03 '17 at 00:38
  • 1
    @SGlavach: If this or any answer has solved your question, please consider upvoting and [accepting it](http://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – sepehr Jan 03 '17 at 00:41