no-referrer-when-downgrade Laravel 5.5

1

This time I come for your help on another topic.

I'm doing a form in Laravel 5.5, to enter a list of servers in a table, This table has many foreign keys.

This is the structure of the table:

<?php $title = isset($item) ? $item->name: "Agregar nuevo Servidor" ?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

{!! Form::myInput('text', 'hostname', 'Hostname', ['required']) !!}
{!! Form::myInput('text', 'ip', 'IP', ['required']) !!}
{!! Form::myInput('text', 'cpu', 'CPU', ['required']) !!}
{!! Form::myInput('text', 'cores', 'Cores', ['required']) !!}
{!! Form::myInput('text', 'ram', 'Ram (MB)', ['required']) !!}
{!! Form::myInput('text', 'disco', 'Disco (GB)', ['required']) !!}
{!! Form::mySelect('id_rol', 'Rol', App\Roles::pluck('nombre', 'id')->toArray(), null, ['class'=>'chosen', 'placeholder' => 'Escoge una opción']) !!}



<div class="row">
  <div class="col-sm-12">
    <div class="box" style="border:1px solid #d2d6de;">
      <div class="box-body" style="margin:10px;">
          <label class="col-sm-5" for="nombre">Sistema operativo</label>
          <br>
            <select name="so" id="so" style="width: 100%">
               <option value="">Seleccionar sistema</option>
                  @foreach($sistemas as $sistema)
                  <option value="{{ $sistema->id }}">{{ $sistema->nombre }}</option>
                  @endforeach
            </select>
            <br>
            <br>
          <label class="col-sm-5" for="nombre">Version Sistema operativo</label>
          <br>
            <select name="version" id="version" style="width: 100%">
               <option value="">Selecciona un sistema operativo primero</option>
            </select>
          <br>
      </div>
    </div>
  </div>
</div>


    <script>

        var rutaConsulta = "{{ route('admin.ruta.consulta.so') }}"; 
        $(document).ready(function(){ 
        selectChange(); 
        }); 

        function selectChange(){ 
        $('#so').on('change', function(e){ 
        var idSo = $(this).val(); 
        ajaxSelect(idSo); 
        }); 
        } 

        function ajaxSelect(id)
        { 
            $.ajax({ 
            type: 'POST', 
            headers: { 
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') 
            },   
            url: rutaConsulta, 
            data: {id: id}, 
            dataType: 'json', 
            beforeSend: function(){ 
            } 
            }).done(function(response) { 
            var html = '<option value="">Selecciona una opción</option>'; 
            $.each(response.versiones, function(i, elem){ 
            html += '<option value="'+ elem.id +'">'+ elem.version +'</option>' 
            }); 
            $('#version').html(html); 
            }).fail(function(data) { 

            }); 
            }


    </script>

{!! Form::mySelect('id_tipo', 'Tipo', App\Tipos::pluck('nombre', 'id')->toArray(), null, ['required','class'=>'chosen', 'placeholder' => 'Escoge una opción']) !!}

{!! Form::mySelect('id_uso', 'Uso', App\Usos::pluck('nombre', 'id')->toArray(), null, ['required','id' => 'listaUsos', 'class'=>'chosen', 'placeholder' => 'Escoge una opción']) !!}

<div class="requerido-con-virtual">
    <div class="row">
  <div class="col-sm-12">
    <div class="box" style="border:1px solid #d2d6de;">
        <div class="box-body" style="margin:10px;">

{!! Form::mySelect('id_padre', 
               'Servidor padre:', 
                App\Servidores::select(DB::raw("ip AS ip"), "id")->where('id_uso', '=', 1)-> pluck('ip', 'id')->toArray(),       
                null, 
               ['class'=>'requerido-con-virtual', 'style' => 'width: 100%;', 'placeholder' => 'Escoge una opción']) !!}
</div>
</div>
</div>
</div>
</div>


<!-- MARCA Y MODELO -->

<div class="requerido-con-fisico">

        <div class="row">
  <div class="col-sm-12">
    <div class="box" style="border:1px solid #d2d6de;">
        <div class="box-body" style="margin:10px;">

<div class="row">
  <div class="col-sm-12">
    <div class="box" style="border:1px solid #d2d6de;">
      <div class="box-body" style="margin:10px;">


<label class="col-sm-5" for="nombre">Marca</label>
<br>
<select name="marca" id="marca" style="width: 100%">
   <option value="">Seleccionar marca</option>
      @foreach($marcas as $marca)
      <option value="{{ $marca->id }}">{{ $marca->nombre }}</option>
      @endforeach
</select>

<br>
<br>

<label class="col-sm-5" for="modelo">Modelo</label>
<select name="modelo" id="modelo" style="width: 100%"> 
<option value="">Selecciona un modelo primero</option> 
</select>

<br>
</div>
</div>
</div>
</div>

<script> 
  var rutaConsulta2 = "{{ route('admin.ruta.consulta.mod') }}"; 
  $(document).ready(function(){ 
  selectChange2(); 
  }); 

  function selectChange2(){ 
    $('#marca').on('change', function(e){ 
    var idMarca = $(this).val(); 
    ajaxSelect1(idMarca); 
    }); 
    } 

  function ajaxSelect1(id){ 
    $.ajax({ 
    type: 'POST', 
    headers: { 
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') 
    } ,
    url:  rutaConsulta2, 
    data: {id: id}, 
    dataType: 'json', 
    beforeSend: function(){ 
    } 
    }).done(function(response) { 
    var html = '<option value="">Selecciona una opción</option>'; 
    $.each(response.modelos, function(i, elem){ 
    html += '<option value="'+ elem.id +'">'+ elem.modelo +'</option>' 
    }); 
    $('#modelo').html(html); 
    }).fail(function(data) { 

    }); 
    }
</script>

{!! Form::myInput('text', 'mac', 'Mac', ['class' => 'requerido-con-fisico', 'style' => 'width: 100%;']) !!}
{!! Form::myInput('text', 'serial', 'Serial', ['class' => 'requerido-con-fisico', 'style' => 'width: 100%;']) !!}
{!! Form::myInput('text', 'ubicacion', 'Ubicación', ['class' => 'requerido-con-fisico', 'style' => 'width: 100%;']) !!}
{!! Form::myInput('text', 'propietario', 'Propietario', ['class' => 'requerido-con-fisico', 'style' => 'width: 100%;']) !!}
</div>
</div>
</div>
</div>
</div>

{!! Form::mySelect('id_estado', 'Estado', App\Estados::pluck('nombre', 'id')->toArray(), null, ['class'=>'chosen', 'placeholder' => 'Escoge una opción']) !!}

{!! Form::myInput('text', 'observacion', 'Observacion', ['required']) !!}

This is my model

class Servidores extends Model
{
    protected $fillable = ['hostname','ip','cpu','cores','ram','disco','id_padre','id_rol','id_so','id_version','id_tipo','id_uso','id_marca','id_modelo','mac','serial','ubicacion','propietario','id_estado','observacion'];

    /*
    |------------------------------------------------------------------------------------
    | Relations
    |------------------------------------------------------------------------------------
    */
    public function parentServidores()
    {
        return $this->belongsTo(Servidores::class);
    }

    public function servidores2()
    {
        return $this->belongsTo('App\Servidores','id_padre');
    }

    public function roles()
    {
     return $this->belongsTo('App\Roles','id_rol');
    }

    public function usos()
    {
     return $this->belongsTo('App\Usos','id_uso');
    }

    public function so()
    {
     return $this->belongsTo('App\SistemasOperativos','id_so');
    }

    public function versionn()
    {
     return $this->belongsTo('App\SoVersiones','id_version');
    }

    public function tipos()
    {
     return $this->belongsTo('App\Tipos','id_tipo');
    }

    public function estados()
    {
     return $this->belongsTo('App\Estados','id_estado');
    }

    public function marcas()
    {
     return $this->belongsTo('App\Marcas','id_marca');
    }

    public function modelos()
    {
     return $this->belongsTo('App\Modelos','id_modelo');
    }



}

This is my driver

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Http\JsonResponse;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Servidores;
use App\Roles;
use App\SistemasOperativos;
use App\SoVersiones;
use App\Tipos;
use App\Marcas;
use App\Modelos;
use App\Estados;


class ServidoresController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $items = Servidores::with('parentServidores','servidores2','roles','so','versionn','marcas','modelos','tipos','estados','usos')->get();

        return view('admin.servidoresVistas.index', compact('items'));
    }



    public function consultarVersiones(Request $request)
    {
       $id_so = $request->id;
       $versiones = SoVersiones::where('id_so', $id_so)->get();


       $respuesta = array();
       $respuesta['versiones'] = $versiones->toArray();   
       return response()->json($respuesta);
    }


    public function consultarModelos(Request $request) 
    { 
        $id_marca = $request->id; 
        $modelos = Modelos::where('id_marca', $id_marca)->get(); 


        $respuesta = array(); 
        $respuesta['modelos'] = $modelos->toArray(); 
        return response()->json($respuesta); 
    }



     /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
       $sistemas = SistemasOperativos::orderBy('nombre','asc')->get();
       $marcas = Marcas::orderBy('nombre','asc')->get();  


    return view ('admin.servidoresVistas.create', compact('sistemas','marcas'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        Servidores::create($request->all());

        //return back()->withSuccess(trans('app.success_store'));
        return redirect()->route(ADMIN.'.servidoresRoute.index')->withSuccess(trans('app.success_store'));

    }

    /**
     * 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)
    {
        $item = Servidores::findOrFail($id);

        return view('admin.servidoresVistas.edit', compact('item'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {

        $item = Servidores::findOrFail($id);
        $item->update($request->all());
        //return back()->withSuccess(trans('app.success_update'));
        return redirect()->route(ADMIN.'.servidoresRoute.index')->withSuccess(trans('app.success_update'));
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        Servidores::destroy($id);

        return back()->withSuccess(trans('app.success_destroy'));
    }


}

And these are my routes:

<?php

Route::get('/', function () {
    return view('home');
});

Route::get('login', function () {
    return view('auth.login');
});

Auth::routes();
Route::get('logout', 'Auth\[email protected]');
/*
|------------------------------------------------------------------------------------
| Admin
|------------------------------------------------------------------------------------
*/
Route::group(['prefix' => ADMIN, 'as' => ADMIN . '.', 'middleware'=>['auth']], function() {
    Route::get('/', ['uses'=>'[email protected]', 'as'=>'dash']);
    Route::get('selectso','[email protected]');
    Route::post('selectversionRoute', '[email protected]')->name('ruta.consulta.so');
    Route::post('selectmodeloRoute', '[email protected]')->name('ruta.consulta.mod');
    Route::get('selectmodeloRoute', '[email protected]')->name('ruta.consulta.mod');
    Route::get('selectversionRoute', '[email protected]')->name('ruta.consulta.so');
    Route::resource('rolesRoute', 'RolesController');
    Route::resource('sisopRoute', 'SisopController');      
    Route::resource('tipoRoute', 'TipoController');
    Route::resource('estadosRoute', 'EstadosController');
    Route::resource('usosRoute', 'UsosController');
    Route::resource('serviciosRoute', 'ServiciosController');
    Route::resource('servidoresRoute', 'ServidoresController');
    Route::resource('instanciasRoute', 'InstanciasController');
    Route::resource('ixsRoute', 'IxsController');
    Route::resource('clientesRoute', 'ClientesController');
    Route::resource('ixclientesRoute', 'IxclientesController');
    Route::resource('soversionesRoute', 'SoversionesController');
    Route::resource('marcasRoute', 'MarcasController');
    Route::resource('modelosRoute', 'ModelosController');
    Route::resource('categories', 'CategoriesController');
    Route::resource('users', 'UsersController')->middleware('Role:Superadmin|Admin');
    Route::get('profileedit/{id}', '[email protected]');
    Route::put('profileupdate/{id}', '[email protected]');


});

Having explained my code, I explain how my error occurs:

I have a table called a server, and this is the form I use to make that income:

When I make that entry, this error occurs:

I have read something about this problem on the internet and it is a topic of routes, but the problem that I initially identify is that when I make that entry, I do not take the data that I select from the operating system, the version or the model or the server mark, despite having taken them.

I'm sorry if the subject is a long one, I would be grateful if someone could help me.

I remain attentive.

Analyzing a little more the problem, I find that I have two punctual lios:

<div class="row">
  <div class="col-sm-12">
    <div class="box" style="border:1px solid #d2d6de;">
      <div class="box-body" style="margin:10px;">
          <label class="col-sm-5" for="nombre">Sistema operativo</label>
          <br>
            <select name="so" id="so" style="width: 100%">
               <option value="">Seleccionar sistema</option>
                  @foreach($sistemas as $sistema)
                  <option value="{{ $sistema->id }}">{{ $sistema->nombre }}</option>
                  @endforeach
            </select>
            <br>
            <br>
          <label class="col-sm-5" for="nombre">Version Sistema operativo</label>
          <br>
            <select name="version" id="version" style="width: 100%">
               <option value="">Selecciona un sistema operativo primero</option>
            </select>
          <br>
      </div>
    </div>
  </div

These fields do not write anything to me on my servers table, and, when I try to edit a field from the page, it does not leave me, so it must be that at the time of doing the get, it does not bring me anything.

How could I fix it to take that data ...

Thanks for reading

Update 3.0:

I already managed to keep the fields in my table, the problem now, it is still with the routes, When I give it to save, it dies, despite having changed its name.

    
asked by Omar Noa 05.09.2018 в 22:02
source

1 answer

2

Apparently it is your routes problem:

Route::post('selectversionRoute', '[email protected]')->name('ruta.consulta.so');
Route::get('selectversionRoute', '[email protected]')->name('ruta.consulta.so');

Where: although one is get and the other post , up there all good.

The name (path.consulta.so) must be different, but if even being "same" you have an even bigger problem directing both ** routes to the same function within the same controller ", Fatal error! !!.

The same thing happens in:

Route::post('selectmodeloRoute', '[email protected]')->name('ruta.consulta.mod');
Route::get('selectmodeloRoute', '[email protected]')->name('ruta.consulta.mod');

Then the solution is to change from name to your routes, and in the same way the functions to which you direct them, something like this:

Route::post('selectversionRoute', '[email protected]')->name('ruta.consulta.so.post');
Route::get('selectversionRoute', '[email protected]')->name('ruta.consulta.so.get');
    
answered by 05.09.2018 / 22:23
source