You cannot load relations when using DB. You need eloquent
$reference = Reference::with('logo')->where('link',$link)->first();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I want to display image which is in my storage field. I want to retrieve this from the database but I get this error:
ErrorException Trying to get property 'url' of non-object
Here is my blade:
<div class="container clearfix">
<div id="oc-clients" class="owl-carousel owl-carousel-full image-carousel carousel-widget" data-margin="30" data-loop="true" data-nav="false" data-autoplay="5000" data-pagi="false" data-items-xs="2" data-items-sm="3" data-items-md="4" data-items-lg="5" data-items-xl="6" style="padding: 20px 0;">
@foreach($reference as $ref)
<div class="oc-item">
<a href="{{ $ref->link }}" target="_blank">
<img src="{{ $ref->logo->url }}">
</a>
</div>
@endforeach
</div>
</div>
Also here is my controller:
public function show($link)
{
$reference =DB::table('references')->where('link',$link)->first();
if($reference){
abort(404);
}
}
And my route:
Route::get('/', function () {
$response= Http::get('https://....../Services/publicapi/getcasecount');
$data = $response->json();
$featuredbox=App\FeaturedBox::all();
$slider=App\Slider::all();
$reference=App\Reference::all();
return view('index',['data'=>$data, 'featuredbox'=>$featuredbox, 'slider'=>$slider, 'reference'=>$reference]);});
How can I access the image truely? Thanks in advance
Please or to participate in this conversation.