Return the same Pagination after a post in Laravel

Asked

Viewed 205 times

1

I have a client page with a button that enables or disables a customer from that list. However if I am on Pag=4 (for example), when active or Deactivate the client I go back to the home page and lose the pagination where I was. Is it possible to post and return the same page? Below is the code of the Controller:

public function alterarStatus(Request $request) {

    if ($request->ativar) {
        $clientes = ClientesRepository::ativarCliente($request->id);
        return redirect()->route('admin.clientes')->with('success', 'Cliente ativado com sucesso');
    }
    $clientes = ClientesRepository::desativarCliente($request->id);
    return redirect()->route('admin.clientes')->with('success', 'Cliente desativado com sucesso');
}

The route 'admin.clients' return the following:

public function clientes() {
    $email = null;
    $nome = null;
    $cidade = null;
    $estado = null;
    $quantidadePorPagina = 10;
    $clientes = ClientesRepository::clientesLista($quantidadePorPagina);
    return view('admin.clientes.clientes', compact('clientes', 'email', 'nome', 'cidade', 'estado'));
}

1 answer

0


Dude you can use Laravel’s own helper, should help you, if it doesn’t help, I’m thinking of storing in Sesssion your last url and return with it.

url()->Previous()

But only if it doesn’t help you.

 public function alterarStatus(Request $request)
    {

        if ($request->ativar) {
            $clientes = ClientesRepository::ativarCliente($request->id);
            return redirect()->to(url()->previous())->with('success', 'Cliente ativado com sucesso');
        }
        $clientes = ClientesRepository::desativarCliente($request->id);
        return  redirect()->to(url()->previous())->with('success', 'Cliente desativado com sucesso');
    }
  • This method worked, however I ended up sending in the formulated the $_GET['page'] and returning the same on the route:

  • Perfect. Very well!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.