iyogesharma/export

Export data in database to various file format

Installs: 106

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:project

1.3 2022-04-04 10:58 UTC

This package is auto-updated.

Last update: 2024-05-04 15:11:20 UTC


README

Export data in database to various file format . Currently xls,json and csv file formats are supported

Example

Using Eloquent
  use YS\Export\Csv;
  use App\User;
  
  public function exportUsers()
  {
      $csv = new Csv( User::select('*'));
      return $csv->response();
  } 
Using DB Facade
  use YS\Export\Csv;
  use App\User;
  
  public function exportUsers()
  {
      $csv = new Csv( DB::table('users')->select('name','email'));
      return $csv->response();
  } 
Using Joins in query
use YS\Export\Csv;
use App\User;
 
 public function exportUsers()
 {
     $query = User::join('companies', 'companies.id','users.company_id')->select('users.name','users.email','companies.name as company');
     $csv = new Csv( $query );
     return $csv->response();
 } 

Similarly you can use Json and Excel export

  use YS\Export\Json;
  use App\User;
  
  public function exportUsers()
  {
      $json = new Json( DB::table('users')->select('name','email'));
      return $json->response();
  } 
  use YS\Export\Xls;
  use App\User;
  
  public function exportUsers()
  {
      $json = new Xls( DB::table('users')->select('name','email'));
      return $json->response();
  } 

You can provide column names inside select statement in order to export only selected columns from database.Optionally you can also define column names inside ys-export config file which you do not want to export in file like id,password etc...

To do this just run php artisan vendor:publish and select ys-export:config group