Jump to content

Laravel Eloquent Model for Ticket "Owner"


eugenevdm

Recommended Posts

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?
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated