title: Laravel 5.4 - How to Responses JSON data with foreign key?
body: <p>I have two tables and I want to response data with a foreign key.</p>
  
  <p>TableCategory</p>
  
  <pre><code>public function up()
      {
          Schema::create('categories', function (Blueprint $table) {
              $table-&gt;increments('id',10);
              $table-&gt;string('name',100)-&gt;nullable();
              $table-&gt;timestamps();
          });
      }
  </code></pre>
  
  <p>TableSong</p>
  
  <pre><code>  public function up()
      {
          Schema::create('songs', function (Blueprint $table) {
              $table-&gt;increments('id',10);
              $table-&gt;string('name',100)-&gt;nullalbe();
              $table-&gt;string('url',500)-&gt;nullalbe();
              $table-&gt;integer('categories_id')-&gt;unsigned();
              $table-&gt;timestamps();
  
              $table-&gt;foreign('categories_id')-&gt;references('id')-&gt;on('categories');
  
          });
      }
  </code></pre>
  
  <p>CategoryModel</p>
  
  <pre><code>class CategoryModel extends Model
  {
      protected $table = 'categories';
      protected $fillable = [
          'id',
          'name',
      ];
      public function song()
      {
          return $this-&gt;hasMany(SongModel::class);   
      }
  }
  </code></pre>
  
  <p>SongModel</p>
  
  <pre><code>class SongModel extends Model
  {
      protected $table = 'songs';
      protected $fillable = [
          'id',
          'name',
          'url',
          'categories_id',
          'singers_id',
          'types_id',
      ];
  
      public function category()
      {
          return $this-&gt;belongsTo(CategoryModel::class, 'categories_id');
      }
  }
  </code></pre>
  
  <p>CategorySongController</p>
  
  <pre><code>class CategorySongController extends Controller
  {
  
      public function index(CategoryModel $categoryModel)
      {
          $song = $categoryModel-&gt;song;
          return response()-&gt;json(['Data' =&gt; $song]);
      }
  
  }
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>SQLSTATE[42S22]: Column not found: 1054 Unknown column
    'songs.category_model_id' in 'where clause' (SQL: select * from
    <code>songs</code> where <code>songs</code>.<code>category_model_id</code> is null and
    <code>songs</code>.<code>category_model_id</code> is not null)</p>
  </blockquote>
  
  <p>My routes</p>
  
  <blockquote>
    <p>Route::resource('/api/v1/categories', 'CategoryController', ['only' =>
    ['index', 'show',]]); Route::resource('/api/v1/categories.songs',
    'CategorySongController', ['only' => ['index']]);</p>
  </blockquote>