Donations Appreciated

There is no exercise better for the heart than reaching down and lifting people up. - John Holmes

Click here to lend your support to: Laravel Datatables and make a donation at pledgie.com !

RelationController.php - Model Belongs To Demo

Id Title Author Email

RelationController.php

    public function getBelongsTo(Request $request)
    {
        if ($request->ajax()) {
            $query = Post::with('user')->select('posts.*');

            return $this->dataTable->eloquent($query)->make(true);
        }

        return view('datatables.relation.belongs-to', [
            'title'      => 'Model Belongs To Demo',
            'controller' => 'Relation Controller',
        ]);
    }

Javascript

    $('#users-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: '',
        columns: [
            {data: 'id', name: 'posts.id'},
            {data: 'title', name: 'posts.title'},
            {data: 'user.name', name: 'user.name'},
            {data: 'user.email', name: 'user.email'}
        ]
    });