title: Laravel how can I make my video_id column equal to id of my videos table?
body: <p>I'm new to laravel, right now I'm stuck on getting video_id on my posts table where I should make it equal to id on my videos table. posts table = <a href="http://imgur.com/a/al2Bv" rel="nofollow">http://imgur.com/a/al2Bv</a> videos table = <a href="http://imgur.com/a/wCNoe" rel="nofollow">http://imgur.com/a/wCNoe</a> Route: displaying video ID when i post it:</p>
  
  <pre><code>Route::get('/test/{videoID}', function($videoID) {
  $video = Video::where('id', $videoID)-&gt;firstOrFail();
  $posts = Post::all();
  return View::make('layouts.viewvideo')-&gt;with(['video' =&gt; $video, 'posts' =&gt; $posts]);});
  </code></pre>
  
  <p>PostController:</p>
  
  <pre><code>public function postCreatePost(Request $request) {
  
      $post = new Post();
      $post-&gt;body = $request['body'];
      $request-&gt;user()-&gt;posts()-&gt;save($post);
      return redirect()-&gt;back();
  </code></pre>
  
  <p>Post view:</p>
  
  <pre><code>@foreach($video-&gt;posts as $post)
          &lt;article class="post" data-postid="{{ $post-&gt;id }}"&gt;
              &lt;div class="postbody"&gt;
                  &lt;p&gt;{{ $post-&gt;body }}&lt;/p&gt;
              &lt;/div&gt;
              &lt;?php
              $test = preg_replace('/([^\s]{20})(?=[^\s])/', '$1'.'&lt;wbr&gt;', $post-&gt;body);
              ?&gt;
              &lt;div class="info"&gt;
                  Posted by {{ $post-&gt;user-&gt;first_name }} on {{ $post-&gt;created_at }}
              &lt;/div&gt;
          &lt;/article&gt;
      @endforeach
  </code></pre>
  
  <p>I tried to edit video_id column on my posts table and change it equal to id of my video and it worked, but how can I automatically assign it once I create post on a specific video? Thank you.</p>