Laravel Excel I do not understand what is being filled

0

I do not understand what's happening in this code that populates a cell B8 in excel:

$sheet->cell('BQ'.$i, function($cell) use($report) {
    $cell->setValue(!empty($report->PastaStatusHistorical->where('status_historical.status','Concluído')->first()) ?
    $report->PastaStatusHistorical->where('status_historical.status','Concluído')->first()->created_at->format('d/m/Y') : '');
});

Is a database or application date being passed?

How do I find this table and column in the bank?

Does this where-> indicate that there is a select?

created_at-> is a method?

What's happening with PastaStatusHistorical ? I go in the template and do not find these 'completed' status fields.

    
asked by anonymous 03.10.2018 / 20:18

1 answer

0

First you need to understand that this type of query is done using Eloquent, it is an ActiveRecord deployment to work with the database, complete documentation is available here ,

I'll start by formatting the code without using the Ternary operator, for larger code snippets I'd rather use if / else for readability.

$sheet->cell('BQ'.$i, function($cell) use($report) {

    if(!empty($report->PastaStatusHistorical->where('status_historical.status','Concluído')->first()) {

        $valor = $report->PastaStatusHistorical->where('status_historical.status','Concluído')->first()->created_at->format('d/m/Y');

    } else {

        $valor = '';

    }

    $cell->setValue($valor);

});

The columns created_at and updated_at are columns managed automatically by Eloquent , they do not need to be referenced in the model, basically when a record is created, the current time of the server will be registered in the created_at column, and when an update happens in that line the updated_at field will be updated.

Yes, where indicates that a query is being made, and first() defines that only the first row found should be returned.

PastaStatusHistorical is a relationship of tables defined in the model, hasMany is a 1: N relationship, if you understand English I suggest reading the official documentation if I did not find this #

03.10.2018 / 21:20