Question about using Blade and Livewire components #444
-
DescriptionHI all, I'm conscious that this might seem like a stupid question but I've really not wrapped my head around augmentation yet, which I guess is at the heart of what I don't understand here. I'm integrating Statamic into an existing Laravel site that is packed with Livewire and Blade components. For the most part the integration has been fine and we've continued using the main Blade layout component and used the I've installed Runway so that editors can create relationships with some of the application's Eloquent models but I'm having trouble using the output of my first Here's what I'm trying in my Blade view: @foreach($featured_listings as $listing)
<livewire:listing-card :listing="$listing" :wire:key="$listing->id" simple="true" />
@endforeach However, This is the fieldtype definition: -
handle: featured_listings
field:
mode: default
resource: listing
create: true
max_items: 2
reorderable: true
type: has_many
display: 'Featured Listings'
listable: hidden
instructions_position: above
visibility: visible
replicator_preview: true
hide_display: false
with:
- 'company' What is the best way to go about using Runway fieldtypes to pass data into Livewire and Blade components? Any advice would be greatly appreciated as I've been going in circles. EnvironmentEnvironment Cache Drivers Statamic Statamic Addons |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
For now I'm just handling this by creating a new blade component to process the raw value of the FeaturedListings.php: class FeaturedListings extends Component
{
public $listings;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct($listings) {
$this->listings = Listing::whereIn('id', $listings->raw())->get();
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.featured-listings');
}
} featured-listings.blade.php: <div class="grid grid-cols-2 gap-4 ">
@foreach($listings as $listing)
<livewire:listing-card :listing="$listing" :wire:key="$listing->id" simple="true" slim="true" />
@endforeach
</div> myview.blade.php:
It works. But I can't help but feel I'm missing a much cleaner way of handling this that would allow me to just include the Livewire component directly in my view file being served by Statamic. Is there? |
Beta Was this translation helpful? Give feedback.
-
The If you want to get the "raw" models themselves, you can do Hopefully that's helpful - let me know if I missed anything. |
Beta Was this translation helpful? Give feedback.
-
Thanks very much for taking the time to respond @duncanmcclean -- also, excellent addon, thank you for sharing it! As per my follow-up comment I'm using What I'm curious about is whether there is a more direct way? i.e. some method that has |
Beta Was this translation helpful? Give feedback.
-
Agreed, thank you
…On Mon, Feb 26, 2024 at 09:33, Duncan McClean ***@***.***(mailto:On Mon, Feb 26, 2024 at 09:33, Duncan McClean <<a href=)> wrote:
I don't think there's an easier way - other than just using Antlers. I'd say ->raw() is probably fine.
—
Reply to this email directly, [view it on GitHub](#444 (reply in thread)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/ABFMYSGGFICCJU4MXZMMDA3YVRJFDAVCNFSM6AAAAABDYVEW32VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DKOJQGA2DM).
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
I don't think there's an easier way - other than just using Antlers. I'd say
->raw()
is probably fine.