We help IT Professionals succeed at work.
Get Started

Could you clear why this Controller method isn't called as expected?

Eduardo Fuerte
on
72 Views
Last Modified: 2020-02-19
Hi Experts


Could you clear why this Controller method isn't called as expected?

Accordingly with a previous question this form have 02 phases

1st: Upload a picture to a defined path - In my tests by using  
use Illuminate\Support\Facades\Storage;

Open in new window

It's perfectly locally uploaded.


2nd  The image url and details must to be saved at the table Vitrines

So, this method is called

Vitrine.prototype.salvar = function(){
    
  console.log ('JS salvar');  // Pass here
  
  $.ajax({
    url: '/admin/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()
    },
    error:function(data){
      hotsite.openModalCustom("Erro", data.responseText, "Entendi", "error");
    },
    success: function(data){
      hotsite.openModalCustom("Sucesso ao salvar", data.retorno, "Entendi", "success");
      hotsite.closeModal('mEditor');
      //hotsite.vitrine.filtrar();
    }
  });
};

Open in new window


img008
This method is configured at routes

Route::post('/admin/vitrine/salvar',['uses'=>'admin\VitrineController@salvar'])->middleware('cadastro');

Open in new window


But it doesn't seen it's called at VitrineController

 public function salvar(Request $request){
 
       info('Em salvar');

       //----------It must to stop here if it's called. But not.
        dd($request);
       //---------------------------------------------

        $id=$request->input('id');
        $url=$request->input('url');
        $inicio=$request->input('inicio');
        $termino=$request->input('termino');

        $titulo = $request->input('title');
        $descricao = $request->input('description');
        $pontuacao = $request->input('points');
  
        try{
            if($id != '' &&  $id > 0){
              $vitrine = Vitrine::find($id);
            }
  
            if(empty($vitrine)){
              $vitrine = new Vitrine();
              $vitrine->created_at=new \DateTime();
            }
                
            $vitrine->title = $titulo;
            $vitrine->description = $descricao;
            $vitrine->points = CustomFuncs::brancoParaNulo($pontuacao);
            $vitrine->url = $url;
            $vitrine->validity_start = empty($inicio) ? null : CustomFuncs::formatarDataUS($inicio);
            $vitrine->validity_end = empty($inicio) ? null : CustomFuncs::formatarDataUS($termino);
            $vitrine->updated_at=new \DateTime();
            
            info($vitrine);
            
            
            $vitrine->save();
  
        } catch (\Exception $e) {
            return response()->json(new Resultado(true,'','Erro ao salvar o vídeo'), 400);
        }
  
        return response()->json(new Resultado(false,'','Vídeo cadastrado com sucesso'));
    
    }

Open in new window



And a success message is presented by the above JS code:
 img007

But nothing is saved at table Vitrines.


Could you check?

Thanks in advance
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2020
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE