Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

435
Views
Laravel Livewire: Possible to use AJAX?

The programming language we've used is: Laravel Livewire.

In the application there's 2 users: 1) Member; 2) Admin.

We have module called "Activities" where the admin can only create,read,update and inactive/active while the Member has a dashboard where they can see all active activities.

I implemented the fullCalendar, I managed to fetch and display the data. Now what I want is when the activity is clicked, it will show the activity details will using modal.

Controller

public function getActivityDetails(Request $request)
    {
        $data                                       = $request->all();
        $activity                                   = Activity::where('id',$data['id']);
        dd($activity);

        return response()->json($activity);
    }

View

<script>
    $(document).ready(function(){
        $.ajaxSetup({
            headers:{
               'X-CSRF-TOKEN' : $('meta[name="csrf-token"]').attr('content')
            }
        });


        var activities = @json($activities);
        var calendar = $('#calendar').fullCalendar({
            header:{
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek, agendaDay'
            },
            events: activities,
            selectable: true,
            selectHelper: true,
            selectable: true,
            eventClick: function(event) {
                if (event.id) {
                    $.ajax({
                        url: "/members-dashboard/getActivityDetails",
                        type: "POST",
                        data: {
                            id: event.id
                        },
                        success:function(data){
                            console.log(data);
                        }
                    })
                }
            }
            // select: function(start, end, allDays){
            //     var value = $(this).val();
            //     console.log(value);
            //     $('#exampleModal').modal('toggle');
            // }

        });

        function successResponse(data)
        {
            calendar.fullCalendar('refetchEvents');
        }
    });

</script>

WEB

use App\Http\Livewire\MembersPortal\MembersDashboard\ActivityDetails;
Route::post('/members-dashboard/getActivityDetails',MembersDashboard::class,'getActivityDetails')->middleware((['auth']));

NOTE: When I tried to console.log the data, it gives me all the html

Question: How can I return the value in my controller?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think that you could use Two components

Activities an ActivitiyDetails components.

The first component will fetch all activities and eager loads activity details at the mount method.

$public Activity $activities;

public function mount(){

 $this->activities= Activity::with('details')->where(...);
}

After that in your view you will have all your activities and the related activitities detail avoiding to use JQuery to fetch detail for each activity.

The second component could be ActivityDetail, which will accept a param of type ActivityDetail object.

In your view

<div>
     @foreach ($activities as $activity)
       <livewire:activity-detail :post="$activity->details">
     @endforeach
</div> 

I hope this help.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!