Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

447
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda