title: Fetch an id from pivot table to use in form builder in laravel
body: <p>I need help to access foreign id in my pivot table to use in form builder select form. I'm trying to create a form when I insert movie and select category then they will be connected when I insert it by fetching category_id from pivot table.</p>
  
  <p>I use many to many relationship and my tables are movies and categories with pivot table category_movie (id, category_id, movie_id). </p>
  
  <p>This is my controller and form.</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>    public function store(Request $request)
  
      {
  
         $request-&gt;user()-&gt;authorizeRoles('admin');   
  
         Movie::create($request-&gt;all());
  
         $categories = Category::pluck('category_name', 'id')-&gt;all();
  
         return view('movies.upload', compact('movies', 'categories'));
  
      }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>   &lt;div class="col-md-6"&gt;
     {{csrf_field()}}
        {!! Form::open(['method'=&gt;'GET', 'action'=&gt; 'MoviesController@store']) !!}
          &lt;div class="form-group"&gt;
             {!! Form::label('name', 'Name:') !!}
             {!! Form::text('name', null, ['class'=&gt;'form-control'])!!}
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
             {!! Form::label ('', 'Category:') !!}
             {!! Form::select('', [''=&gt;'Choose Categories'] + $categories, null, ['class'=&gt;'form-control']) !!}
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
             {!! Form::submit('Insert Movie', ['class'=&gt;'btn btn-primary']) !!}
          &lt;/div&gt;
        {!! Form::close() !!}
     &lt;/div&gt;
  </code></pre>