troubleshooting Question

Could you point why a Laravel Controller method produces an error when another similar runs correctly?

Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil asked on
5 Comments1 Solution75 ViewsLast Modified:
Hi Experts

Could you point why a Laravel Controller method produces an error when another similar runs correctly?

Accordingly to:

function Vitrine() {}

Vitrine.prototype.salvar = function(){
    url: '/vitrine/salvar',
    method: "POST",
    data: {
      _token: $('input[name="_token"]').val(),
      id: $('#id').val(),
      url: $('#url').val(),
      inicio: $('#inicio').val(),
      termino: $('#termino').val(),
      title: $('#title').val(),
      description: $('#description').val(),
      points: $('#points').val()
      hotsite.openModalCustom("Erro", data.responseText, "Entendi", "error");
    success: function(data){
      hotsite.openModalCustom("Sucesso ao salvar", data.retorno, "Entendi", "success");

// This doesn't runs correctly
Vitrine.prototype.minhasfotos = function(){
    url: '/vitrine/minhasFotos',
    method: "GET",
    dataType: "html",
      hotsite.openModalCustom("Erro", "Erro ao carregar vitrine.", "Entendi", "error");
    success: function(data){

Laravel routes:
Route::post('/vitrine/salvar',['uses'=>'VitrinesController@salvar'])->middleware('cadastro');   // OK
Route::post('/vitrine/minhasfotos',['uses'=>'VitrinesController@minhasFotos'])->middleware('cadastro');  //NOK

//This route apparently is called somehow....

VitrinesController methods:
// Runs correctly
 public function salvar(Request $request){
        info("Em salvar...");


        $titulo = $request->input('titulo');
        $descricao = $request->input('descricao');
        $titulo = $request->input('title');
        $descricao = $request->input('description');
        //$pontuacao = $request->input('points');
            if($id != '' &&  $id > 0){
              $vitrine = Vitrine::find($id);
              $vitrine = new Vitrine();
              $vitrine->created_at=new \DateTime();
            $vitrine->titulo = $titulo;
            $vitrine->descricao = $descricao;
            $vitrine->url = $url;
            $vitrine->updated_at=new \DateTime();

            $vitrine->criador_id = auth()->user()->id;

        } catch (\Exception $e) {
            return response()->json(new Resultado(true,'','Erro ao salvar a foto'), 400);
        return response()->json(new Resultado(false,'','Sua foto foi enviada para análise da Copagaz, se for aprovada a foto ficará visível para todos os participantes.'));
// This method generates an error with  apparently no relation with VitrinesController (but with VitrineController)

    public function minhasFotos(Request $request){
		// Just to check call
        info('em minhasFotos');

Web page
Runs OK
        <button type="button" class="btn btn-primary" onclick="hotsite.vitrine.salvar();"><i class="fas fa-hdd" aria-hidden="true"></i> Salvar</button>
Generates Error
		<button type="button" class="btn btn-primary" onclick="hotsite.vitrine.minhasfotos();">

The error pointed at another Controller (VitrineController.php)



Could you check and point a workaround?

Thanks in advance
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros