Donations Appreciated

When we give cheerfully and accept gratefully, everyone is blessed. - Maya Angelou

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

EloquentController.php - Has Many

Id Title Author Name Email Created At Updated At

EloquentController.php

    public function getHasMany()
    {
        return view('datatables.eloquent.has-many');
    }

    public function getHasManyData()
    {
        $posts = User::first()->posts()->with('user');

        return Datatables::of($posts)
            ->editColumn('title', '{!! str_limit($title, 60) !!}')
            ->make(true);
    }

Javascript

    $('#posts-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: 'https://datatables.yajrabox.com/eloquent/has-many-data',
        columns: [
            {data: 'id', name: 'id'},
            {data: 'title', name: 'title'},
            {data: 'user.name', name: 'name', orderable: false, searchable: false},
            {data: 'user.email', name: 'email', orderable: false, searchable: false},
            {data: 'created_at', name: 'created_at'},
            {data: 'updated_at', name: 'updated_at'}
        ]
    });