Excel

Excel import-export tools

Back to Excel Support

akshay.solutiontree27438
akshay.solutiontree27438

function onGenerateExcel() {

 try{

$items = post();
        $record_id=$items['id'];
        $queries = Db::table('trip')
        ->select('trip.id as trips_id','trip.unique_id as unique_id','trip.date_start as date_start','trip.date_end as date_end','products_orders.status as status', 'uemura_locations_cities.city_name as city_name','users.name as names','products_orders.invoice_number as invoice_number','trip.created_at as created_at')
        ->leftJoin('users', 'trip.user_id', '=', 'users.id')
        ->leftJoin('uemura_locations_cities', 'trip.city_id', '=', 'uemura_locations_cities.id')
        ->leftJoin('products_orders', 'trip.id', '=', 'products_orders.trip_id')
        ->where('trip.id', '=', $record_id)
        ->get();

//print_r($queries); die('okay');

         foreach($queries as $data) {
           $tripid = $data->trips_id;
           $uniqueid = $data->unique_id;
           $datestart = $data->date_start;
           $dateend = $data->date_end;
           $status = $data->status;
           $cityname = $data->city_name;
           $names = $data->names;
           $invoicenumber = $data->invoice_number;
           $createdat = $data->created_at;

                                    }

                    $data = [
                       'trips_id' => $tripid,
                       'unique_id' => $uniqueid,
                       'date_start' => $datestart,
                       'date_end' => $dateend,
                       'status' => $status,
                       'city_name' => $cityname,
                       'names' => $names,
                       'invoice_number' => $invoicenumber,
                       'created_at' => $createdat
                       ];

                 $excel->sheet('Sheet', function($sheet) {

                   $sheet->fromModel($data);

                        });

}

catch (Exception $e) { Flash::error($e->getMessage()); }

}
vdomah
vdomah

Depends on what you want to do, it's not clear for me. More details you can find on http://www.maatwebsite.nl/laravel-excel/docs

akshay.solutiontree27438
akshay.solutiontree27438

i m using in components

  • on this i get the id on the behalf of id i put join condition and fetch all data after data in controller i put this code <?php namespace watchlearn\travelinvoice\components;

    use Cms\Classes\ComponentBase; use Input; use Validator; use Redirect; use Flash; use DB; use Renatio\DynamicPDF\Classes\PDF; use Vdomah\Excel\Classes\Excel; class Travelinvoice extends ComponentBase

    {

    public function componentDetails(){
    
            return[
    
              'name'=> 'Travelinvoice',
    
              'Description'=> 'Travelinvoice'
    
            ];  
    
    }

    public function onGenerateExcel() {

     try{
    
    $items = post();
            $record_id=$items['id'];
            $queries = Db::table('trip')
            ->select('trip.id as trips_id','trip.unique_id as unique_id','trip.date_start as date_start','trip.date_end as date_end','products_orders.status as status', 'uemura_locations_cities.city_name as city_name','users.name as names','products_orders.invoice_number as invoice_number','trip.created_at as created_at')
            ->leftJoin('users', 'trip.user_id', '=', 'users.id')
            ->leftJoin('uemura_locations_cities', 'trip.city_id', '=', 'uemura_locations_cities.id')
            ->leftJoin('products_orders', 'trip.id', '=', 'products_orders.trip_id')
            ->where('trip.id', '=', $record_id)
            ->get();
    
    //print_r($queries); die('okay');
    
             foreach($queries as $data) {
               $tripid = $data->trips_id;
               $uniqueid = $data->unique_id;
               $datestart = $data->date_start;
               $dateend = $data->date_end;
               $status = $data->status;
               $cityname = $data->city_name;
               $names = $data->names;
               $invoicenumber = $data->invoice_number;
               $createdat = $data->created_at;
    
                                        }
    
                        $data = [
                           'trips_id' => $tripid,
                           'unique_id' => $uniqueid,
                           'date_start' => $datestart,
                           'date_end' => $dateend,
                           'status' => $status,
                           'city_name' => $cityname,
                           'names' => $names,
                           'invoice_number' => $invoicenumber,
                           'created_at' => $createdat
                           ];
        Excel::excel()->load(base_path() . '/storage/app/media/file.xlsx', function($data) {
    
                    $results = $data->all();

    });

    }

    catch (Exception $e) { Flash::error($e->getMessage()); }

    }

    but it give me nothing

    1-3 of 3