Skip to content
Advertisement

Print specific data to blade view

I can’t find how to print data on the blade.view. I have a list of “customers” on overview.blade.php, and I have a button that redirects to their profile based on their “nCustomerID” (which is blade.view for me).

When I use the dump function on blade.view page does show the correct data for each ” customer” I have in my database, but I don’t know how to print it on the blade.view. Would love to get some documentation or explanation to read along on this.

Controller:

    public function show($id)
    {
        $oCustomer = Customer::getCustomer($id);
        return view('Customers.view', ['nCustomerID' => $id]);
    }

Advertisement

Answer

Using Compact() methods to show data in Laravel blade view.

public function show($id)
{
    $oCustomer = Customer::getCustomer($id);
    return view('Customers.view',compact('oCustomer');
}

In view try this way.

 /*if oCustomer is a collection */
 @foreach($oCustomer as $customer)
     {{$customer->name}}
 @endforeach

 /* if oCustomer is a single object*/
 {{$oCustomer->name}} or {{$oCustomer[0]->name}}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement