PHP code example of samdevbr / laravel-bigreport

1. Go to this page and download the library: Download samdevbr/laravel-bigreport library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

samdevbr / laravel-bigreport example snippets


// config/app.php

// ...

Illuminate\View\ViewServiceProvider::class,

/*
 * Package Service Providers...
 */
Samdevbr\Bigreport\BigreportServiceProvider::class,

// ...


use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $table = 'post';

    public function author()
    {
        return $this->belongsTo(User::class);
    }
}

use Samdevbr\Bigreport\Fields\FieldCollection;
use Samdevbr\Bigreport\Fields\BelongsTo;
use Samdevbr\Bigreport\Fields\Text;

$fields = [
  Text::make('Post ID', 'id'),
  Text::make('Title', 'title'),
  Text::make('Description', 'description'),
  BelongsTo::make('Author', 'author.name'),
];

$fieldCollection = FieldCollection::make($fields);

use Samdevbr\Bigreport\Fields\FieldCollection;
use Samdevbr\Bigreport\Fields\BelongsTo;
use Samdevbr\Bigreport\Fields\Text;

$fields = [
  Text::make('Post ID', 'id'),
  Text::make('Title', 'title'),
  Text::make('Description', 'description', function ($description) {
    return str_limit($description, 20);
  }),
  BelongsTo::make('Author', 'author.name'),
];

$fieldCollection = FieldCollection::make($fields);

use App\Post;

$export = Post::export($fieldCollection);

return $export->download('filename.csv');