I'm trying to populate a datatable, but I'm not doing it at all. Could you help me?
============= Evaluator_Report - Model ========
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Avaliativo_Relatorio extends Model
{
protected $connection = 'mysql2';
protected $fillable = [
'id',
'firstname',
'lastname',
'email',
'courseid',
'fullname'
];
}
============= Evaluator_ReportController - Controller ========
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Avaliativo_Relatorio;
use Yajra\DataTables\Facades\DataTables;
class Avaliativo_RelatorioController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('relatorios_ava.avaliativo_relatorio');
}
public function get_datatable_avaliativo()
{
$avaliativo = Avaliativo_Relatorio::table('mdl_role_assignments')
->join('mdl_context', 'mdl_role_assignments.contextid', '=', 'mdl_context.id')
->join('mdl_course', 'mdl_course.id', '=', 'mdl_context.instanceid')
->join('mdl_user', 'mdl_user.id', '=', 'mdl_role_assignments.userid')
->where('mdl_context.contextlevel','=',50)
->where('mdl_role_assignments.roleid','=',5);
return Datatables::of($avaliativo)->make(true);
}
}
============= Evaluative_report.blade ========
ID Name Last name Email Id course Course============= master.blade ========
<script type="text/javascript">
$(document).ready(function() {
$('#users-table-avaliativo').DataTable({
"language": {
"lengthMenu": "Exibindo _MENU_ registros por página",
"zeroRecords": "Nada encontrado - desculpe",
"info": "Exibindo página _PAGE_ de _PAGES_",
"infoEmpty": "Nenhum registro disponível",
"infoFiltered": "(filtrado de _MAX_ total registros)",
"sLoadingRecords": "Carregando Registros...",
"sProcessing": "Processando...",
"sSearch": "Pesquisar",
"oPaginate": {
"sFirst": "Primeira",
"sPrevious": "Anterior",
"sNext": "Próxima",
"sLast": "Última"
}
},
"processing": true,
"serverSide": true,
"ajax": "{{ route('relatorios_ava.avaliativo_relatorio.get_datatable_avaliativo') }}",
"columns":[
{"data": "id"},
{"data": "firstname"},
{"data": "lastname"},
{"data": "email"},
{"data": "courseid"},
{"data": "fullname"}
]
});
});
</script>