eugenevdm Posted July 28, 2015 Share Posted July 28, 2015 In our company a ticket is pretty useless until it has been assigned (flagged in WHMCS) to an employee (admin in WHMCS). So we have a dedicated person who assigns (flags) tickets. As soon as a ticket is flagged the tbltickets.flag contains the tbladmin.id of the employee. I'm trying to recreate an Eloquent model that resembles this. I've called this "owner" so as not to confuse with the built-in field called 'admin' which is the originator of the ticket (if any). The problem is owner doesn't produce any data so I guess I am doing something fundamentally wrong. I have: <?php namespace App; use Illuminate\Database\Eloquent\Model; class Ticket extends Model { protected $table = 'tbltickets'; public function owner() { return $this->belongsTo('App\Admin'); } } as my Ticket model and <?php namespace App; use Illuminate\Database\Eloquent\Model; class Admin extends Model { protected $table = 'tbladmins'; public function tickets() { return $this->hasMany('App\Ticket','flag'); } } as the Admin model. In my blade I try to loop over crucial data about old tickets, i.e. in the Controller I have: $oldest_tickets = Ticket::where('flag','<>', 0)->where('Status','!=','Answered')->where('Status','!=','Closed')->orderBy('lastreply','ASC')->get(); and then in the blade I have: @foreach($oldest_tickets as $ticket) <tr> <td> {{ $ticket->lastreply() }} </td> <td> <a href="{{ $ticket->url() }}" target="_blank">#{{ $ticket->tid . ' - ' . $ticket->title }}</a> </td> <td> {{ $ticket->userid }} </td> <td> {{ $ticket->name }} </td> <td> {{ $ticket->email }} </td> <td> {{ $ticket->owner }} </td> </tr> @endforeach However, this doesn't work, $ticket->owner doesn't produce any data. Any clues? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.