Function does not work within class [Laravel]

Asked

Viewed 75 times

0

I’m trying to call one function inside another in one of the controllers of my Laravel project, but when the flame the page is all blank and presents no error.

public function index()
    {
      $departamentos = Departamento::all();
      $clientes = Cliente::all()->sortByDesc("id");
      $lastCliente = Cliente::all()->sortByDesc("id")->first();
      return view('clientes', compact('clientes','departamentos','lastCliente'));
    }


public function store(Request $request)
    {
        $cliente = new Cliente();
        $cliente->nome = $request->input('nomeCliente');
        $cliente->idade = $request->input('idadeCliente');
        $cliente->departamento_id = $request->input('idDepartamento');
        $cliente->descricao = $request->input('descricaoCliente');
        $cliente->save();
        $this->index(); <-----------
    }

1 answer

1

You must return a redirect.

return redirect()->route('index.route...');

Redirect to index route... It is wrong to simply call the index method inside the store (because this is a post), you should redirect pro index method.

Browser other questions tagged

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