Maybe is kind of simple but currently I show last message and message from like this
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>User</th>
<th style="width: 100px">Last from</th>
</tr>
</thead>
<tbody>
@foreach($messages as $message)
<tr @if(!$message->from_admin && !$message->read_state) class="info" @endif>
<td>{{ $message->message_id }}</td>
<td>{{ $message->user->username }}</td>
<td>{{ $message->from_admin ? 'Admin' : '<span class="name-highlight">User</span>' }}</td>
</tr>
@endforeach
</tbody>
</table>
I want to make Admin
variable from database. So in my controller I have this so far
public function messages() {
$query = Message::
whereRaw('messages.message_id = (select max(message_id) from `messages` m2 where m2.user_id = messages.user_id)')
->orderBy('message_id', 'desc')
->get();
return View::make('site.admin.messages', [
'messages' => $query
]);
}
In message Model
public function user() {
return $this->belongsTo('User', 'user_id', 'user_id');
}
In admin table I have column called is_admin
which is 1
for admin and 0
for all other users.
What I'm trying to display is Admin
name from database here
<td>{{ $message->from_admin ? 'Admin' : '<span class="name-highlight">User</span>' }}</td>
Can anyone help how to do that?