Support the ongoing development of Laravel.io →
Eloquent Blade Forms
Last updated 2 years ago.
0

Did you try maatwebsite/excel gitub plugin ?

0

Yes it is installed. The problem is i cannot get examples how to send the detail (excel file) to the view and then export it without needing to send all the report criteria again to an export controller.

0

If possible can you share your code to sending the detail to view ?

0

I will as soon as i get home. Thanks spider.

0

This is the code in my controller


$report_total = Termsale::Daterange($request->startdate, $request->enddate)
                                                ->where('type', '=', $request->type)
                                                ->where('cust_id', '=', Auth::user()->id)
                                                ->sum('amount');

$report = Termsale::Daterange($request->startdate, $request->enddate)->orderBy('id', 'desc')
                                    ->where('type', '=', $request->type)
                                    ->where('cust_id', '=', Auth::user()->id)
                                    ->with('shopmarname', 'smename')
                                    ->get();

return view('admin.reports.reports', compact('report', 'report_total'));

Last updated 8 years ago.
0

I can now save a file to server like this:

 Excel::create(Auth::user()->id, function($excel) use($report){
                    $excel->sheet('1', function($sheet) use($report){
                        $sheet->fromArray($report);
                        });
                })->store('xls', false, true);

The problem is that it does not export the relations data that is in $report and i display it in my view like this:

{{ $info->shopmarname->name }} {{ $info->shopmarname->surname }} <- This is not in the export but in $report

To export the file i am going to put a link on the view pointing to the file on the server.

Last updated 8 years ago.
0

Use the following code. Just replace the reoprts variable as per the your view code. Please match paranthesis () before use.

 Excel::create(Auth::user()->id, function($excel) use($report){
                    $excel->sheet('1', function($sheet) use($report){
                         $sheet->loadView('you view here', array('pageTitle' => 'Transaction History', 'reports' =>$report));
                        });
                })->export('xls');

Thanks

Last updated 8 years ago.
0

Thanks for that code spider. I do not know if loadView is suppose to show an excel spreadsheet, it just went straight to download, but at least i had all the data now that i could export. Tyvm for your help.

0

Please ... I am new at laravel and I have the same problem ... I followed your advice step by step .. but does not work in my case ... could help ...?

My route

Route::get('cacharro/{id}', ['as' => 'pagina', 'uses' => 'ExcelController@index']);

My link

<a class="btn btn-success" href="{{ route('pagina', ['id' => $results]) }}">Excel</a>

My view


<div class="panel-body">
                <table class="table table-striped table-condensed table-responsive table-bordered">
                    <thead>
                        <tr>
                            <th>Nombre</th>
                            <th>Pais</th>
                            <th>Tipo</th>
                            <th>CC_PMC</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($results as $result)
                        <tr>
                            <td>{{$result->nom}}</td>
                            <td>{{$result->pais}}</td>
                            <td>{{$result->tipo_cont}}</td>
                            <td>{{$result->cc_pmc}}</td>
                        </tr>
                        @endforeach
                    </tbody>
                    
                </table>
                <a class="btn btn-success" href="{{ route('pagina', ['id' => $results]) }}">Excel</a>
            </div>

and finally.. my controller (ExcelController)


class ExcelController extends Controller
{
    public function index($id){
        
        Excel::create('New file', function($excel) use($id) {
            $excel->sheet('New sheet', function($sheet) use($id) {
                $sheet->loadView('listados.listados', ['results' => $id->toArray()]);
            });
        })->download('xls');
    }
}

the error I get is ... Sorry, the page you are looking for could not be found.... NotFoundHttpException in RouteCollection.php line 161....

what's going on...? because it does not work ...? please help...!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

AtomicRSA atomicrsa Joined 24 Jun 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.