Home > Mobile >  Pass Anonymous Components Attribute as object
Pass Anonymous Components Attribute as object

Time:09-22

I have a Blade Anonymous Component.

I want to pass an attribute to the components as object.

When I do this, the object converts to string

The component file:

@props(['object'])

{{ $object }}

The component call:

<x-component object="object variable" />

CodePudding user response:

Try like this, prepending a : before the attribute name. Example:

welcome.blade.php

@php 
  $customer = (object)['name' => 'Kenny'];
@endphp
<x-customer-component :customer="$customer"/>
                      ^

customer-component.blade.php

<div>
  <p>Hey, my name is {{ $customer->name }}</p>
</div>
  • Related