title: Laravel 5.4 hide something from other users
body: <p>I'm working on an application where the user has projects assigned to him, which he sees on his website. After clicking on a given project, it is moved to the page of this project where the url looks like eg ./project/22 - 22 is the id of the project. The problem is that another user entering in the search engine eg / project / 22 can see this project even though it is not assigned to it. I also have a pivot table where the project id and user id are stored. This is my code to show project:
  Controller:</p>
  
  <pre><code>public function projects($id)
      {
          $project = Project::findOrFail($id);
         return view('pages.project')-&gt;with('project', $project);
      }
  </code></pre>
  
  <p>Project model:</p>
  
  <pre><code>public function users()
      {
          return $this-&gt;belongsToMany('App\User')-&gt;withTimestamps();
      }
  </code></pre>
  
  <p>user model:</p>
  
  <pre><code>public function projects()
      {
          return $this-&gt;belongsToMany('App\Project')-&gt;withTimestamps();
      }
  </code></pre>
  
  <p>web.php:</p>
  
  <pre><code> Route::get('/projects/{id}', 'PagesController@projects');
  </code></pre>