Laravel : Join two tables get the info from table one and get the first related image from table two
<p>I have two table one is <code>propertyDetails</code> and the other is <code>propertyImages</code>
and I have done the relation between the two tables like so..</p>

<p>here is the models</p>

<p><strong>propertyDetails</strong></p>

<pre><code>class PropertyDetail extends \Eloquent {
    protected $fillable = [];

    public function propImages()
    {
        return $this-&gt;hasMany('PropertyImage', 'property_details_id');
    }
}
</code></pre>

<p><strong>Table migration</strong></p>

<pre><code>public function up()
    {
        Schema::create('property_details', function (Blueprint $table) {
            $table-&gt;increments('id');
            $table-&gt;enum('purpose', array('Sell', 'Rent'));
            $table-&gt;integer('property_owner_id')-&gt;unsigned();
            $table-&gt;integer('property_agent_id')-&gt;nullable();
            $table-&gt;integer('bedroom');
            $table-&gt;integer('dining_room');
            $table-&gt;integer('bathroom');
            $table-&gt;string('title', 100);
            $table-&gt;integer('price');
            $table-&gt;string('type', 120);
            $table-&gt;string('specify_type', 120);
            $table-&gt;text('details');
            $table-&gt;integer('active');
            $table-&gt;foreign('property_owner_id')-&gt;references('id')-&gt;on('property_owners')-&gt;onDelete('cascade');
            $table-&gt;timestamps();
        });
    }
</code></pre>

<p><strong>propertyImages</strong></p>

<pre><code>class PropertyImage extends \Eloquent
{
    protected $fillable = [];

    public function propertyImages()
    {
        return $this-&gt;belongsTo('PropertyDetail', 'property_details_id');
    }
}
</code></pre>

<p><strong>Table migration</strong></p>

<pre><code>Schema::create('property_images', function(Blueprint $table)
        {
            $table-&gt;increments('id');
            $table-&gt;integer('property_details_id')-&gt;unsigned();
            $table-&gt;foreign('property_details_id')-&gt;references('id')-&gt;on('property_details')-&gt;onDelete('cascade');
            $table-&gt;binary('image');
            $table-&gt;timestamps();
        });
    }
</code></pre>

<p>what I want to do is select all the <code>projectsDetails</code> with the first related image from table two <code>propertyImages</code></p>

<p>I tried</p>

<pre><code>$properties = PropertyDetail::with('propImages')-&gt;get();
return View::make('admin.properties.view', compact('properties'));
</code></pre>

<p>and in my view</p>

<pre><code>@foreach($properties as $property)
{{ HTML::image('images/propertyImages/'.$property-&gt;propImages-&gt;image, $property-&gt;title, array('width'=&gt;767, 'height'=&gt;384)) }}
@endforeach
</code></pre>

<p>got</p>

<blockquote>
  <p>Undefined property: Illuminate\Database\Eloquent\Collection::$image</p>
</blockquote>