title: laravel user list with posts and profile links
body: <p>I try to get list of all users with post and link them to different page where all their posts is listed.</p>
  
  <p>Obviously I must make my list page first then my users detail page, but some how I ended up with detail page and no list page :)))</p>
  
  <p>Anyway: this is what I have so far:</p>
  
  <p><code>Controller</code></p>
  
  <pre><code>public function chef() {
        //
        return view('front.chef');
      }
  
      public function chefdetail($username) {
    $foods = Food::whereHas('user', function($q) use($username){
      $q-&gt;where('username',$username);
    })-&gt;get();
    return view('front.chef-detail', compact('foods'));
  }
  </code></pre>
  
  <p>My routes:</p>
  
  <pre><code>Route::get('/chef/{username}', 'FrontendController@chefdetail')-&gt;name('chefdetail');
  Route::get('/chefs', 'FrontendController@chef')-&gt;name('chefs');
  </code></pre>
  
  <p><strong>Questions (Problems) :</strong></p>
  
  <ol>
  <li>How do I get list of users with posts in my <code>chef</code> function?</li>
  <li>How do I add <code>username</code> to my chefs detail page URL</li>
  </ol>
  
  <blockquote>
    <p>Is it correct that I used <code>$user = User::find(1);</code> to getting users list? because I couldn't get users by id it returns error.</p>
  </blockquote>