title: How to create a relationship between models for ticket system in laravel
body: <p>I am trying to make a ticketing system and I am working on showing the tickets a user has. The way the relationship works now is that the tickets are assigned to a user who's then assigned to a campus. I actually need it to to be where the tickets are assigned to the campus since the campus is definite, and have a tech assigned to that campus. The tech should only see the tickets that belongs to the campus that the tech is assigned to.</p>
  
  <p>In theory, it should work like if a user is changed or relocated then all that needs to be done is update the <code>TechID</code> column. Here is how the table relationship works currently:</p>
  
  <ul>
  <li>Tickets (PK - TicketID, FK - CampusID) </li>
  <li>Campus (PK - CampusID, FK - TechID) </li>
  <li>User (PK - TechID)</li>
  </ul>
  
  <p>I actually have a similar question that I asked before, but this was before I realized that the way it was structured before isn't the ideal setup.</p>
  
  <p>Here is the link to the previous question: <a href="https://stackoverflow.com/questions/53838769/how-to-join-three-tables-with-laravel-and-keep-data-integrity/53838905?noredirect=1#comment94531558_53838905">Previous Question</a></p>
  
  <p>Here is my current controller:</p>
  
  <pre><code>namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use Auth;
  
  use App\User;
  use App\Campus;
  use App\Ticket;
  
  class PagesController extends Controller
  {
  
      /**
       * Create a new controller instance.
       *
       * @return void
       */
      public function __construct()
      {
          $this-&gt;middleware('auth');
      }
  
      // Dashboard Page
      public function index()
      {
      $user = User::with(['campuses' =&gt; function($query) {
          $query-&gt;select(['TechID', 'CampusName']);
      },'tickets'])-&gt;where('id', Auth::id())-&gt;first();
  
      $campuses = Campus::all()-&gt;where('TechID', $user-&gt;id);
      $tickets = Ticket::all()-&gt;where('CampusID', $campuses-&gt;pluck('CampusID'));
  
      return view('home')-&gt;with([
         'user' =&gt; $user,
         'campuses'=&gt;$campuses,
         'tickets'=&gt;$tickets]);
      }
      // Queue Page
      public function Queue() {
          return view('Pages.Queue');
      }
      // Reports Page
      public function Reports() {
          return view('Pages.Reports');
      }
      // Search Page
      public function Search() {
          return view('Pages.Search');
      }
  }
  </code></pre>
  
  <p>I was hoping this would work, but no tickets actually show up. The user can have more than one campus so I was wondering if maybe this is where things are messing up. Any help is much appreciated</p>