WallyJ

Interesting, and depressing...

I get the quotation marks again. Even when I change the case of the "Contactnotes"

JoaoPedroAS51

@WallyJ I don't know, try to change the name Contactnotes to notes in Model/Controller

JoaoPedroAS51

@WallyJ Try

$contacts = Contact::with('deals.tasks')->find($id);

$contacts->loadMissing('contactnotes');

dd($contacts->contactnotes);
JoaoPedroAS51

@WallyJ Don't give up, keep trying!

WallyJ

Thanks for the encouragement.

Still quotation marks.

It's something simple. Just can't figure it.

JoaoPedroAS51

@WallyJ Maybe it have some conflict with this name, what

#attributes: array:26 [▶]

returns when dd($contacts); ?

And it is not contacts is contact because you get a specific contact with find($id)

WallyJ

Again, the contact notes were working before I tried to add the tasks. It was at that point I wasn't writing the code correctly to also request the tasks. That's when I was encouraged to use this:

$contacts = Contact::with(['contactnotes', 'deals.tasks')->find($id);

Which was your cleaned up version. :)

So I know the relationships were working and the contactnotes were being found.

JoaoPedroAS51
Sergiu17

@WallyJ now it's different. Do you have in

#attributes: array:26 [▶]

an attribute called contactnotes ? which is " " ( empty ) ?

JoaoPedroAS51

@WallyJ Maybe use your old version with some modifications, until we fix the problem

public function show($id)
{
        $contact = Contact::find($id);

        $contactnotes = Contactnote::where('contact_id', $contact->id)->orderBy('created_at', 'desc')->get();
        $deals = Deal::where('contact_id', $contact->id)->with('tasks')->get();

        // Check for correct user
        if(auth()->id() !== $contact->user_id){
            return redirect('/contacts')->with('error', 'That Is Not Your Contact');
        }

        return view('contacts.show', compact('contact', 'contactnotes', 'deals'))
} 
        
WallyJ

Wow... mystery solved...

I had a lingering old field in my contacts table called "contactnotes" when I originally created the table, before I created an entirely different table for "contactnotes". I changed the name of the field, and boom, everything worked as expected.

DD in the controller, then DD in the view, then the view itself.

Thanks guys! #newbmistakes #greatcommunity #thankful

WallyJ

@Sergiu17 , Follow up. Though this line works beautifully and cleanly, I just noticed that I lost my "orderBy('created_at', 'desc'), and can't figure out how to put it back in to order the contactnotes.

$contacts = Contact::with(['contactnotes', 'deals.tasks'])->find($id);

Or do I handle the sorting in this line?

return view('contacts.show', ['contact' => $contacts, 'contactnotes' => $contacts->contactnotes, 'deals' => $contacts->deals]);

Please sign in or create an account to participate in this conversation.