app/DataTables/ReportsDataTable.php
/**
     * Get query source of dataTable.
     *
     * @param \App\Admin $model
     * @return \Illuminate\Database\Eloquent\Builder
     */
Get query source of dataTable.
Get query source of dataTable .
public function query()
    {
        $q =    MiseFound::query()
            ->leftJoin('users', 'users.id', '=', 'missing_found.user_id')
            ->leftJoin('categories', 'categories.id', '=', 'missing_found.category_id_fk')
            ->leftJoin('countries as city', 'city.id', '=', 'missing_found.city_id_fk')
            ->leftJoin('countries as govern', 'govern.id', '=', 'missing_found.govern_id_fk')
            ->select('missing_found.*', 'users.name as u_name', 'categories.name as cat_name', 'city.title as city_title','govern.title as govern_title');
        if ((request()->has('report_with'))) {
            if (request()->has('month')) {
                $currnetData = $q->whereMonth('missing_found.created_at', '=', request('month'));
            }
            if (request()->has('year')) {
                $currnetData = $q->whereYear('missing_found.created_at', '=', request('year'));
            }
            if (request()->has('from') && request()->has('to')) {
                $currnetData = $q->whereBetween('missing_found.created_at', array(request('from'), request('to')));
            }
        }else if (request()->has('now')) {
            $currnetData = $q->whereDate('missing_found.created_at', '=', date('Y-m-d'));
        }
         else {
            $currnetData = $q;
        }
        return $currnetData;
    }
public function query ( ) { $ q = MiseFound :: query ( ) -> leftJoin ( 'users' , 'users.id' , '=' , 'missing_found.user_id' ) -> leftJoin ( 'categories' , 'categories.id' , '=' , 'missing_found.category_id_fk' ) -> leftJoin ( 'countries as city' , 'city.id' , '=' , 'missing_found.city_id_fk' ) -> leftJoin ( 'countries as govern' , 'govern.id' , '=' , 'missing_found.govern_id_fk' ) -> select ( 'missing_found.*' , 'users.name as u_name' , 'categories.name as cat_name' , 'city.title as city_title' , 'govern.title as govern_title' ) ; if ( ( request ( ) -> has ( 'report_with' ) ) ) { if ( request ( ) -> has ( 'month' ) ) { $ currnetData = $ q -> whereMonth ( 'missing_found.created_at' , '=' , request ( 'month' ) ) ; } if ( request ( ) -> has ( 'year' ) ) { $ currnetData = $ q -> whereYear ( 'missing_found.created_at' , '=' , request ( 'year' ) ) ; } if ( request ( ) -> has ( 'from' ) && request ( ) -> has ( 'to' ) ) { $ currnetData = $ q -> whereBetween ( 'missing_found.created_at' , array ( request ( 'from' ) , request ( 'to' ) ) ) ; } } else if ( request ( ) -> has ( 'now' ) ) { $ currnetData = $ q -> whereDate ( 'missing_found.created_at' , '=' , date ( 'Y-m-d' ) ) ; } else { $ currnetData = $ q ; } return $ currnetData ; }
Get query source of dataTable.
Get query source of dataTable .
//return User::query(); //$q = DB::table('missing_found')