How to make the project Laravel see the axios file?

0

Before I was having trouble making the project see the file as you can see in this post:

I need make my Javascript file see the vue and axios files

He was like this:

Andnowit'slikethis,ithasbeenfixed:

Thechangewastoputthefileaxiosandvueintherootofthelibfolderandputthetwoimportsasyoucanseebelow;

window.Vue=require('vue');window.Axios=require('axios');varcrud=newVue({el:'#crud',created:function(){this.getRegistros();},data:{...

Butheonlyconnectedthefilevueandlefttheaxioswithoutconnecting,whyamIstatingthis?Well,ifyoudosubmittheformsandsavethefilesinthedatabaseit'sAxiosandthesystemisbehavingwrongagain,I'llexplain:

FirstofallIwillshowmyapp.jsfilewhichhasallthemethods:

window.Vue=require('vue');window.Axios=require('axios');varcrud=newVue({el:'#crud',created:function(){this.getRegistros();},data:{registros:[],newDesc:'',newPreco:'',newQtdQuartos:'',newTipo:'',newFinalidade:'',newLogradouroEndereco:'',newBairroEndereco:'',preencherRegistro:{'id':'','descricao':'','preco':'','qtdQuartos':'',tipos:'',//achoquemeuproblemaestáaqui******'finalidade':'',//achoquemeuproblemaestáaqui******'logradouroEndereco':'','bairroEndereco':''},errors:[]},methods:{getRegistros:function(){varurlRegistro='imovels';axios.get(urlRegistro).then(response=>{this.registros=response.data});},editarRegistro:function(registro){/*alert(registro.tipos);*/this.preencherRegistro.id=registro.id;this.preencherRegistro.descricao=registro.descricao;this.preencherRegistro.preco=registro.preco;this.preencherRegistro.qtdQuartos=registro.qtdQuartos;this.preencherRegistro.tipos=registro.tipos;this.preencherRegistro.finalidade=registro.finalidade;this.preencherRegistro.logradouroEndereco=registro.logradouroEndereco;this.preencherRegistro.bairroEndereco=registro.bairroEndereco;$('#edit').modal('show');},updateRegistro:function(id){varurl='imovels/'+id;axios.put(url,this.preencherRegistro).then(response=>{this.getRegistros();this.preencherRegistro={'id':'','descricao':'','preco':'','qtdQuartos':'',tipos:'','finalidade':'','logradouroEndereco':'','bairroEndereco':''};this.errors=[];$('#edit').modal('hide');toastr.success('Tareaactualizadaconéxito');}).catch(error=>{this.errors='Corrijaparapodereditarconéxito'});},createRegistro:function(){varurl='imovels';axios.post(url,{descricao:this.newDesc,preco:this.newPreco,qtdQuartos:this.newQtdQuartos,tipos:this.newTipo,finalidade:this.newFinalidade,logradouroEndereco:this.newLogradouroEndereco,bairroEndereco:this.newBairroEndereco}).then(response=>{this.getRegistros();this.newDesc='';this.newPreco='';this.newQtdQuartos='';this.newTipo='';this.newFinalidade='';this.newLogradouroEndereco='';this.newBairroEndereco='';this.errors=[];$('#create').modal('hide');//efetuaraexecuçãotoastr.success('Novoimóvelcriadocomsucesso!');}).catch(error=>{this.errors=error.response.data});},deletarRegistro:function(registro){varurl='imovels/'+registro.id;axios.delete(url).then(response=>{this.getRegistros();toastr.success('Registroexcluídocomsucesso');});}}});/*varurl='imovels';axios.delete(url).then(response=>{this.getRegistros();toastr.success('Egistroexcluído');});*/

WhenIclicktheNewPropertybutton,itappearsbelow:

Whenthisformisfilleditdoesnotsavetheregistry,andwhenIgotoinspectthepageitpresentserror500asaninternalURLerrorimovels

Inmylocalcomputeritworksnormally,themethodthatsavestherecordsiscalledcreateRegistro,youcanseeitintheapp.jsfileandintheformasyoucanseebelow

p>
<formmethod="POST" v-on:submit.prevent="createRegistro">


  @section('content')
          @if($errors->any())
              <div class="alert alert-danger" role="alert">
                  @foreach ($errors->all() as $error)
                      {{ $error }}<br>
                  @endforeach
              </div>
          @endif


      <div class="modal fade" id="create" tabindex="2" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-lg ">
                <div class="modal-content">
                    <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal">
                          <span>&time;</span>
                      </button>
                      <h4>Novo Imóvel</h4>
                    </div>
                    <div class="modal-body">

                            <label for="descricao">Criar Imóvel</label>
                            <input type="text" name="descricao"placeholder="Descrição do imóvel" class="form-control" v-model="newDesc" required>


                                      <div class="row">
                                          <div class="col-md-6">
                                              <div class="form-group">
                                                  <label for="preco">Preço</label>
                                                  <input type="text" class="form-control" placeholder="Preço" name="preco" v-model="newPreco" required>
                                              </div>
                                          </div>
                                          <div class="col-md-6">
                                              <div class="form-group">
                                                  <label for="qtdQuartos">Quantidade de Quartos</label>
                                                  <input type="number" class="form-control" placeholder="Quantidade de Quartos" name="qtdQuartos" v-model="newQtdQuartos" required>
                                              </div>
                                          </div>
                                      </div>

                                    <div class="row">
                                          <div class="col-md-6">
                                                <div class="form-group">
                                                      <label for="tipos">Tipo do Imóvel</label>
                                                      <select class="form-control" name="tipos" v-model="newTipo" required>
                                                      <option selected>Apartamento</option>
                                                      <option>Casa</option>
                                                      <option>Kitnet</option>
                                                    </select>
                                                </div>
                                          </div>

                                          <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label for="finalidade">Finalidade do imóvel</label>
                                                        <select class="form-control" name="finalidade" v-model="newFinalidade" required>
                                                            <option>Venda</option>
                                                            <option>Locação</option>
                                                        </select>
                                                    </div>
                                                <span v-for="error in errors" class="text-danger">@{{ error }}</span>
                                          </div>
                                    </div>

                                    <h4>Endereço</h4>
                                    <hr>

                                      <div class="form-group">
                                              <label for="logradouroEndereco">Logradouro</label>
                                              <input type="text" class="form-control" placeholder="Logradouro" name="logradouroEndereco" v-model="newLogradouroEndereco" required>
                                      </div>
                                      <div class="row">
                                          <div class="col-md-10">
                                              <div class="form-group">
                                                  <label for="bairroEndereco">Bairro</label>
                                                  <input type="text" class="form-control" placeholder="Bairro" name="bairroEndereco"  v-model="newBairroEndereco" required>
                                              </div>
                                          </div>
                                      </div>

                    </div>


                    <div class="modal-footer">
                        <input type="submit" class="btn btn-primary" value="Salvar">
                    </div>
                </div>
            </div>
        </div>
</form>

Again I strongly believe that the problem is Axios configuration because in my local computer it works normally, I need to know exactly what to change in the project for the axios to be seen.

===================================================== ==========

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Imovel;


class ImovelController extends Controller
{






    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $imovels = Imovel::get();
        return $imovels;
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
      $this->validate($request, [
          'descricao' => 'required'
      ]);

      Imovel::create($request->all());
      return;
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $imovel = Imovel::findOrFail($id);
        return $imovel;
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
              $this->validate($request, [
                'descricao' => 'required',
            ]);
            Imovel::find($id)->update($request->all());
            return;
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $imovel = Imovel::findOrFail($id);
        $imovel->delete();
    }
}
    
asked by anonymous 01.11.2017 / 11:08

1 answer

1

My advice is to use vuex, besides being a good practice will help you not have bugs like this. The internet has several examples is very simple and advantageous.

    
04.11.2017 / 19:37