Hola, estoy teniendo un problema sumamente raro, ayer me sucedio lo mismo, todo funcionaba perfecto ayer a la manaña me puse a trabajar y un modulo no funciona... hoy me paso lo mismo con el mismo modulo.
es un datatable, no me carga la lista de clientes y no se porqué... (repito ayer estaba funcionando y no he tocado nada de hecho no tiene fecha de modificación tampoco)
CustomerController:
Código PHP:
use AppHttpRequests;
use AppCustomer;
use IlluminateSupportFacadesRedirect;
use AppHttpRequestsCustomerFormRequest;
use DB;
use YajraDatatablesDatatables;
class CustomerController extends Controller
{
public function index()
{
return view('admin.sale.customer.index');
}
public function getCustomers()
{
$customers = Customer::select(['id','name','type_doc','num_doc','mobile','class']);
return Datatables::of($customers)
->addColumn('action', function($row){
$btn = '<a href="/public/customers/'.$row->id.'"><button class="btn btn-success">Ver</button></a>';
$btn = $btn. ' <a href="/public/customers/'.$row->id.'/edit" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="Edit"><button class="btn btn-info">Editar</button></a>';
$btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="Delete"><button class="btn btn-danger">Eliminar</button></a>';
return $btn;
})
->rawColumns(['action'])
->make(true);
}
}
Customer.php (Model)
Código PHP:
class Customer extends Model
{
protected $table='customers';
protected $primaryKey="id";
public $timestamps=true;
protected $fillable =[
'type_customer',
'name',
'type_doc',
'num_doc',
'address',
'telephone',
'mobile',
'whatsapp',
'class',
'note',
'email'
];
protected $guarded =[
];
}
View:
Código PHP:
<table id="customers" class="table table-bordered table-striped">
<thead>
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Tipo de Doc</th>
<th>Documento</th>
<th>Celular</th>
<th>Clase</th>
<th>Opciones</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Tipo de Doc</th>
<th>Documento</th>
<th>Celular</th>
<th>Clase</th>
<th>Opciones</th>
</tr>
</tfoot>
</table>
<script type="text/javascript">
$(document).ready(function() {
oTable = $('#customers').DataTable({
"processing": true,
"serverSide": true,
"ajax": "{{ route('datatable.customers') }}",
"columns": [
{data: 'id', name: 'id'},
{data: 'name', name: 'name'},
{data: 'type_doc', name: 'type_doc'},
{data: 'num_doc', name: 'num_doc'},
{data: 'mobile', name: 'mobile'},
{"name": "class", "data": "class", "render": function (data, type, full, meta)
{
return "<img src=\"{{asset('/dist/img/status/customer/status')}}" + data + ".png\" height=\"25\" width=\"25\"/>";
},},
{data: 'action', name: 'action'}
]
});
});
</script>
Web.php (Route)
Código PHP:
Route::resource('/customers', 'Admin\CustomerController');
Route::get('/customers', 'Admin\CustomerController@index');
Route::get('/getcustomers', 'Admin\CustomerController@getCustomers')->name('datatable.customers');
El error en consola es este:
Código:
http://127.0.0.1/public/getcustomers?draw=1&columns%5B0%5D%5Bdata%5D=id&columns%5B0%5D%5Bname%5D=id&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=name&columns%5B1%5D%5Bname%5D=name&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=type_doc&columns%5B2%5D%5Bname%5D=type_doc&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=num_doc&columns%5B3%5D%5Bname%5D=num_doc&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=mobile&columns%5B4%5D%5Bname%5D=mobile&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B5%5D%5Bdata%5D=class&columns%5B5%5D%5Bname%5D=class&columns%5B5%5D%5Bsearchable%5D=true&columns%5B5%5D%5Borderable%5D=true&columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B6%5D%5Bdata%5D=action&columns%5B6%5D%5Bname%5D=action&columns%5B6%5D%5Bsearchable%5D=true&columns%5B6%5D%5Borderable%5D=true&columns%5B6%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B6%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1557405564908 500 (Internal Server Error)
y al entrar a 127.0.0.1/public/getcustomers (que debería devolver el json, tira este error)
Código:
Method App\Http\Controllers\Admin\CustomerController::getCustomers does not exist.
pero como verán el method si existe... lo que me llama la atención es que he copiado y pegado este codigo en otros 10 sectores y los otros 10 sectores siguen funcionando sin problemas...