bgultekin / laravel-datatables-bundle

Laravel Datatables Bundle helps to handle server-side works of Datatables Jquery Plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option to call function

Thijmen opened this issue · comments

Hi,

I want to make a datatable of an object. I wrote a function in the model that I want to run on 1 column. How do I do that?

Sorry but, I don't understand. Can you share more information about what you want to do.

This is my model:

<?php

class Project extends Eloquent {

public static function getTotalHours($proj_id, $checkin = "", $checkout = "")
    {   
        $sql = "SELECT SUM(TIME_TO_SEC(TIMEDIFF(checkout, checkin))) AS total FROM hours WHERE project_id = $proj_id";
        if($checkin != "" && $checkout != "")
        {
            // checkin and checkout
            $sql .= " AND checkin >= $checkin AND checkin <= $checkout";
        }
        return DB::first($sql);
    }

With datatables I want do run that function to a column (lets say, id). How do I do that? $id->gettotalHours wouldn't do it.

If I didn't missunderstand, there is no way to do this in datatables bundle, for now.
Because, everything (included sorting, filtering) use eloquent,fluent to do its work.

But you can create this query by using eloquent or fluent. Try to use DB::raw() where it is required.

Lastly, sorry for late reply.