I want to fetch only one columns which has name image_url from relationship table. relationship on table is belongsTO.
i am confused how to fetch only single column value with belongsTo relation.
below is my model.
<?php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
class PropertyImageGallery extends Model
{
use HasFactory;
protected $fillable = ['property_id', 'name', 'size','image_url'];
public function property()
{
return $this->belongsTo(Property::class);
}
}
please help me.
3
Answers
BelongsTo relationship like below:
it would be:
you should call it like this in your controller :
check this for more infos: Eloquent: Relationships (Belongs To)
You can try this: