I would like to know how I can show data from two tables in a single datatable?
In the "user" part, it would be the user's name but it belongs to another table
This is what I have in my controller
namespace App \ Http \ Controllers;
use Illuminate\Http\Request;
use Datatables;
use App\Usuario;
use DB;
use App\Resultado;
class DataTablesController extends Controller
{
/**
* Displays datatables front end view
*
* @return \Illuminate\View\View
*/
public function datatable()
{
return view('usuarios.resultado');
}
public function getPosts()
{
$model = Usuario::query();
// return datatables()->eloquent(Usuario::query())->toJson();
return Datatables::eloquent($model)
->addColumn('action', function($user) {
return '
<br><a href="' . route('VerResultado', $user->id_usu) . '" class="btn btn-xs btn-success" title="Detalles">Ver Detalles</a>
';
})
->toJson();
}
public function getRes()
{
$resultado = Resultado::query();
return Datatables::eloquent($resultado)
->toJson();
}
}
And this is basically the ajax function.
$('#resultado').DataTable({
dom: 'Bfrtip',
"procesing": true,
"serverside": true,
responsive: true,
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
],
"ajax": '{{ route('datatable/getres') }}',
"columns":[
{data: 'id', name: 'id'},
{data: 'sintetico', name: 'sintetico'},
{data: 'idealista', name: 'idealista'},
{data: 'pragmatico', name: 'pragmatico'},
{data: 'analitico', name: 'analitico'},
{data: 'realista', name: 'realista'},
{data: 'total', name: 'total'},
{data: 'id_usu', name: 'id_usu'},
],
order: [[0, 'asc']]
});
});