Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

438
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda