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

305
Visualizações
How to filter data on request in laravel 8?

I've in my React component this function:

const url = '/category';


function hideOnClick(id) {
  setHide({value: id})
  console.log(id);
  const body = {
      'chordId' : id,
  }

  const requestMetadata = {
      method: 'POST',
      headers: {
          'Content-Type': 'application/json'
      },
      body: JSON.stringify(body)
    };
    console.log(body);

  fetch(url, requestMetadata)
    .then(res => res.json())
    .then(res => {
        this.setState({
            url: res
        })
        console.log(res);
    })
}

In my route/web this line:

Route::post('/category', [PostController::class, 'postBody']);

And finally in my PostController this function

public function postBody(Request $request)
{
    $chord = $request->get('chordId');

    $posts = Post::join('categories', function ($builder) {
        $builder->on('categories.id', '=', 'posts.category_id');
    })
    ->where('name', '=', Str::before($chord, '.'))
    ->get();


    return view("posts.index-category")->with(array("posts" => $posts));
}

I have this graph dynamically rendered with categories and I want to make it interactive and used to filter posts based on where the user click on the graph.

Right now in my network tab I'm able to see the fetch request with a status of 200, and in the preview I see my view index-category with the correct posts, based on the filter in my PostController.

But I don't know how to show this result in my page without a full page refresh. I think I've to use something like ajax but I don't know how. Someone has any suggest?

about 4 years ago · Juan Pablo Isaza
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