<?php

namespace DummyNamespace;

use Carbon\Carbon;
use App\Http\Controllers\Controller;
use Yajra\DataTables\Facades\DataTables;
use DummyRepositoryNamespace;
use DummyManageRequestNamespace;

/**
 * Class DummyTableController.
 */
class DummyTableController extends Controller
{
    /**
     * variable to store the repository object
     * @var dummy_repository
     */
    protected $dummy_small_repo_name;

    /**
     * contructor to initialize repository object
     * @param dummy_repository $dummy_small_repo_name;
     */
    public function __construct(dummy_repository $dummy_small_repo_name)
    {
        $this->dummy_small_repo_name = $dummy_small_repo_name;
    }

    /**
     * This method return the data of the model
     * @param dummy_manage_request_name $request
     *
     * @return mixed
     */
    public function __invoke(dummy_manage_request_name $request)
    {
        return Datatables::of($this->dummy_small_repo_name->getForDataTable())
            ->escapeColumns(['id'])
            ->addColumn('created_at', function ($dummy_small_repo_name) {
                return Carbon::parse($dummy_small_repo_name->created_at)->toDateString();
            })
            ->addColumn('actions', function ($dummy_small_repo_name) {
                return $dummy_small_repo_name->action_buttons;
            })
            ->make(true);
    }
}
