Support the ongoing development of Laravel.io →
posted 8 years ago
Database

Hi guys,

Been trying to find solution to my "problem" so I hope you can help me. So I have this model that stores certain stuff and it has like 5 rows that are basically id's of users from user table, so when I render for a record of the model the view I pass entire row like:

public function show($id) {
$user = User::find($id);
$sales = Sale::where('customer_id', '=', $id)->get();
return view('profiles.customer', ['user' => $user, 'sales' => $sales]);
}

And in blade I get all those sales like:

@foreach ($sales as $sale)
    <li>
        <i class="fa fa-home bg-blue"></i>
        <div class="timeline-item">
            <span class="time"><i class="fa fa-clock-o"></i> {{$sale->created_at->format('g:ia, M jS Y')}}</span>

            <h3 class="timeline-header"><a href="#">{{$user->name}}</a> became a customer</h3>

            <div class="timeline-body">
                <p>Date: {{$sale->sold_date}}</p>
                <p>Price: {{$sale->sale_price}}</p>
            </div>
        </div>
    </li>
@endforeach

But inside each record I have like "account_manager_id", "agent_id", "owner_id", "plan_id" so I guess I'm trying to get somehow those ID's that are returned inside @foreach to query Users table (and Plan for plan_id, it's different model and table) and get a name from there.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

dinocsp dinocsp Joined 17 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.