laravellaravel-5

Custom Function call at controller not working


This is the first time I try to do my own function, and seems that something is wrong at the function calling because I only see a blank screen.

I want to make a search of a user, all that data will be displayed at the rigth when clicking the "Buscar" button. The data to look for is at the input control up the button (The image is atteched down).

This are my routes

    Route::resource('escuelausuarios','EscuelaUsuariosController');
    Route::get('registroaccesos/search/{$patron}', 'RegistroAccesosController@search')->name('registroaccesos.search');     
    Route::get('registroaccesos/otra/', 'RegistroAccesosController@otra')->name('registroaccesos.otra');        
    Route::resource('registroaccesos','RegistroAccesosController');

I send you the index function where the call is defined, with javascript. I guess there's something wrong with action

<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
   <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#">Grupos</a>
</nav>
<div class="container-fluid">
<div class="row">
<nav class="col-sm-2 d-md-block bg-light sidebar">
<div class="sidebar-sticky">
<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
   <span>Acciones</span>
   <a class="d-flex align-items-center text-muted" href="#">
   <span data-feather="plus-circle"></span>
   </a>
</h6>
<div class="form-group">
   <label for="strSearch" class="col-form-label">Patrón de búsqueda</label>
   <select name="strSearch" class="form-control">
      <option value="1"  selected> Código del usuario</option>
      <option value="2"  > Nombre del usuario</option>
   </select>
</div>
<div class="form-group">
   <input  placeholder="Patrón de búsqueda"
      id="strPatron"
      required
      name="strPatron"
      spellcheck="false" 
      class="form-control"
      />
</div>
<button class="btn btn-sm btn-outline-secondary"
   onclick="
   event.preventDefault();
   document.getElementById('search-form').submit();
   "
   >Buscar</button>
<form id="search-form" action="{{ route('registroaccesos.otra'  ) }}"
   method="POST" style="display: none;">
   <input type="hidden" name="_method" value="delete">
   {{ csrf_field() }}
</form>

This is the function (otra) is being called when clicking "Buscar" Button.

public function search($patron="")
{
    //
    $patron = 'Hola';
    dd($patron);
    return;
}

public function otra()
{
    //
    
    dd(1);
    return;
}

enter image description here

Seems the call is taking place when clicking "Buscar" button but as I told you, I only see a blank screen.

enter image description here


Solution

  • You have created a route of GET request which is:

    Route::get('registroaccesos/otra/', 'RegistroAccesosController@otra')->name('registroaccesos.otra');
    

    You are submitting POST request through the form that's why it is unable to handle that request.

    Try changing your GET request to POST as follows:

    Route::post('registroaccesos/otra/', 'RegistroAccesosController@otra')->name('registroaccesos.otra');