Livewire

Anyone can help me passing data into view with livewire? I have a resumes.index and I need to pass data from 2 tables.
17 Replies
Patrick Boivin
Patrick Boivin10mo ago
Can you share some code to show what you've been trying?
einnlleinhatt_
einnlleinhatt_10mo ago
I have 2 tables educations and experiences.
Livewire App
<?php

namespace App\Livewire\Resumes;

use App\Models\Education;
use App\Models\Experience;
use Illuminate\View\View;
use Livewire\Component;

class Index extends Component
{
public function render(): View
{
return view('livewire.resumes.index', [
'educations' => Education::all(),
'experiences' => Experience::all()
]);
}
}
Livewire App
<?php

namespace App\Livewire\Resumes;

use App\Models\Education;
use App\Models\Experience;
use Illuminate\View\View;
use Livewire\Component;

class Index extends Component
{
public function render(): View
{
return view('livewire.resumes.index', [
'educations' => Education::all(),
'experiences' => Experience::all()
]);
}
}
Livewire View
<div class="custom-container">
<div class="resume-content content-width">
<div class="section-header">
<h4 class="subtitle scroll-animation" data-animation="fade_from_bottom">
<i class="las la-briefcase"></i> Resume
</h4>
<h1 class="scroll-animation" data-animation="fade_from_bottom">Education & <span>Experience</span></h1>
</div>

<div class="resume-timeline">
@foreach($educations as $education)
<div class="item scroll-animation" data-animation="fade_from_right">
<span class="date">{{ $education->start_date }} - {{ $education->end_date }}</span>
<h2>{{ $education->degree }} - {{ $education->institution }}</h2>
<p>Brunodee Agency</p>
<span class="date">2020 - Present</span>
<h2>Front-End WordPress Developer</h2>
<p>Envato Market</p>
</div>
@endforeach
</div>
</div>
Livewire View
<div class="custom-container">
<div class="resume-content content-width">
<div class="section-header">
<h4 class="subtitle scroll-animation" data-animation="fade_from_bottom">
<i class="las la-briefcase"></i> Resume
</h4>
<h1 class="scroll-animation" data-animation="fade_from_bottom">Education & <span>Experience</span></h1>
</div>

<div class="resume-timeline">
@foreach($educations as $education)
<div class="item scroll-animation" data-animation="fade_from_right">
<span class="date">{{ $education->start_date }} - {{ $education->end_date }}</span>
<h2>{{ $education->degree }} - {{ $education->institution }}</h2>
<p>Brunodee Agency</p>
<span class="date">2020 - Present</span>
<h2>Front-End WordPress Developer</h2>
<p>Envato Market</p>
</div>
@endforeach
</div>
</div>
I tried to use 2 foreach but the output is not what I want
Patrick Boivin
Patrick Boivin10mo ago
I think this looks ok... passing the collections to the view and then looping over with a foreach. What is the issue?
einnlleinhatt_
einnlleinhatt_10mo ago
I need to pass the experience too
awcodes
awcodes10mo ago
Should just be available as $experiences Just like $educations is available
einnlleinhatt_
einnlleinhatt_10mo ago
Here is my goal.
No description
awcodes
awcodes10mo ago
So you want to merge the two?
einnlleinhatt_
einnlleinhatt_10mo ago
Yeah, it is possible ?
awcodes
awcodes10mo ago
Yes, but this isn’t a livewire issue and you’ll need to look up a proper way to use eloquent to join them together coming out of the db, especially if you want to group them by years. Honestly, I’m not sure of the best way to achieve that with two separate models. But I know it’s possible.
Patrick Boivin
Patrick Boivin10mo ago
@einnlleinhatt_ Is this a very long page with a lot of items or just a few education + experience combined?
awcodes
awcodes10mo ago
Is there a need to even have these as records in the db.? Personally, I would do the whole section as a rich text and just style it with css.
einnlleinhatt_
einnlleinhatt_10mo ago
Its a long page with few sections.
Patrick Boivin
Patrick Boivin10mo ago
Good point. Or even a use a Repeater field with a "type" sub-field (education vs. experience) for each item.
awcodes
awcodes10mo ago
That could work too. I’m seeing it in Tiptap editor as just details that could be styled and even collapsible. 🙂
Patrick Boivin
Patrick Boivin10mo ago
The reason I'm asking is because it could be easier to combine the items in plain PHP, instead of in the DB. If you don't have thousands and thousands of line items, it should be quite fast and simple code. Does that make sense?
awcodes
awcodes10mo ago
But there could be a reason for the delineation, but I’m not seeing it in the screenshot.
einnlleinhatt_
einnlleinhatt_10mo ago
I see, thankyou for the feedback.
Want results from more Discord servers?
Add your server
More Posts