Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Josadec's avatar

Invalid Argument Exception

Good afternoon everyone,

I have this situation with my Laravel project when I trieing to export to Excel using the Laravel Excel with by view, doesn't work, I have the message

"InvalidArgumentException View [exports.excel.'nameview'.php] not found. " But the file is there in the correct path, I don't understand why I have this error.

Someone could help me to fix this problem

0 likes
14 replies
MohamedTammam's avatar

Are you sure that the file resources/view/exports/excel/nameview.blade.php exists? and how are you calling it?

Josadec's avatar

@MohamedTammam I not sure if this blog have option to be able to add photos to send you a picture with file explorer show the file in path

achatzi's avatar

@josadec Are there single quotes in the view name?

"InvalidArgumentException View [exports.excel.'nameview'.php] not found. "

Or is it a copy paste thing?

Josadec's avatar

@achatzi Yes I copy and pasted, this time added my view name

InvalidArgumentException
View [exports.excel.reportperanswer.php] not found.
http://norma035asi.test/export/reports/countperanswers

Josadec's avatar

@Sinnbeck

Yes of course Web file

/****************** Export to Excel ***************/
Route::get('/export/excel',[ExportExcelController::class,'exportToExcel'])->name('exportoexcel');
Route::get('/export/calificacion',[ExportExcelController::class,'exportPerScort'])->name('totalScort');
Route::get('/export/dimensionstoexcel',[ExportExcelController::class,'dimensionsTotals'])->name('dimensionstoexcel');
Route::get('/export/globalreport',[ExportExcelController::class,'reporteGlobal'])->name('globalreport');
Route::get('/export/categoriestoexcel',[ExportExcelController::class,'globalCategries'])->name('categoriestoexcel');
Route::get('/export/domainstoexcel',[ExportExcelController::class,'globalDomains'])->name('domainstoexcel');
Route::get('/export/categoriesperanswers',[ExportExcelController::class,'countAnswersPerCategories'])->name('countPerCategories');
Route::get('/export/domainsperanswers',[ExportExcelController::class,'countAnswersPerDomains'])->name('countPerDomains');
Route::get('/export/reports/countperanswers',[ExportExcelController::class,'countAnswerPerExams'])->name('reportExams');

Class ExportExcelController

<?php

namespace App\Http\Controllers;

use App\Exports\AnswerApplicationExportQuery;
use App\Exports\AnswersReport;
use App\Exports\CategoriesExport;
use App\Exports\categoriesExportPerAnswers;
use App\Exports\DimensionsTotals;
use App\Exports\DomainsExport;
use App\Exports\domainsExportPerAnswers;
use App\Exports\QuestionsExport;
use App\Exports\ScoreTotal;
use Maatwebsite\Excel\Facades\Excel;

class ExportExcelController extends Controller
{
    public function exportToExcel()
    {
        $fecha = date('m_d_Y');
        $filename = "CalificacionesTotales_";
        return Excel::download(new AnswerApplicationExportQuery, $filename.$fecha.'.xlsx');
    }

    public function dimensionsTotals(){
        $fecha = date('m_d_Y');
        $filename = "DimensionsTotales_";
        return Excel::download(new DimensionsTotals, $filename.$fecha.'.xlsx');
    }

    public function globalCategries(){
        $fecha = date('m_d_Y');
        $filename = "CategoriesTotales_";
        return Excel::download(new CategoriesExport,$filename.$fecha.'.xlsx');
    }

    public function globalDomains(){
        $fecha = date('m_d_Y');
        $filename = "DominiosTotales_";
        return Excel::download(new DomainsExport, $filename.$fecha.'.xlsx');
    }

    public function reporteGlobal()
    {
        $fecha = date('m_d_Y');
        $filename="ReporteGlobal_";
        return Excel::download(new QuestionsExport, $filename.$fecha.'.xlsx');
    }

    public function exportPerScort()
    {
        $fecha = date('m_d_Y');
        $filename = "ExamenesContadosXcalificacion_";
        return Excel::download(new ScoreTotal, $filename.$fecha.'.xlsx');
    }
    public function countAnswersPerCategories ()
    {
        $fecha = date('m_d_Y');
        $filename = "CategoriasXRespuesta_";
        return Excel::download(new categoriesExportPerAnswers,$filename.$fecha.'.xlsx');
    }
    public function countAnswersPerDomains ()
    {
        $fecha = date('m_d_Y');
        $filename = "DominiosXRespuestas_";
        return Excel::download(new domainsExportPerAnswers, $filename.$fecha.'.xlsx');
    }
    public function countAnswerPerExams ()
    {
        $fecha = date('m_d_Y');
        $filename = "RespuestasContadasPorExamen_";
        return Excel::download(new AnswersReport, $filename.$fecha.'.xlsx');
    }
}

Class AnswersReport

<?php

namespace App\Exports;

use App\Models\Answer;
use Illuminate\View\View;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromView;

class AnswersReport implements FromView
{
    use Exportable;

        public function view (): View
        {
             $answers =  Answer::join('questions', 'answers.question_id', '=', 'questions.id')
             ->join('answer_application', 'answer_application.answer_id', '=', 'answers.id')
             ->selectRaw('questions.id AS question_id, questions.description AS question_name,
                                 answers.description AS answer_name,
                                 count(*) as total')
             ->groupByRaw('answers.id, questions.id, questions.description, answers.description')
             ->orderby('question_id')
             ->get(); 
     
             $preguntas = [];
     
             foreach ($answers as $answer) {
                 $preguntas[str_replace(' ','',$answer->answer_name)][$answer->question_id] = $answer->total;
             }
     
             $data['answers'] = $answer;
             $data['preguntas'] = $preguntas;
     
             return view('exports.excel.reportperanswer.php',$data);
        }
   
}

View reportperanswer


<table>
    <thead>
    <tr>
        <th>#</th>
        <th>Pregunta</th>
        <th>Siempre</th>
        <th>Casi Siempre</th>
        <th>Algunas veces</th>
        <th>Casi nunca</th>Tyler
        <th>Nunca</th>
    </tr>
    </thead>
    <tbody>
    @php
        $preQuestion=null;
    @endphp
    
     @foreach($answers as $answer)
         @if($preQuestion!=$answer->question_id)
             @php $preQuestion=$answer->question_id; @endphp
             <tr>
                 <td>{{ $answer->question_id }}</td>
                 <td>{{ $answer->question_name."?" }}</td>
                 <td>{{ $preguntas['Siempre'][$answer->question_id]??0}}</td>
                 <td>{{ $preguntas['Casisiempre'][$answer->question_id]??0}}</td>
                 <td>{{ $preguntas['Algunasveces'][$answer->question_id]??0}}</td>
                 <td>{{ $preguntas['Casinunca'][$answer->question_id]??0}}</td>
                 <td>{{ $preguntas['Nunca'][$answer->question_id]??0}}</td>
             </tr>
        @endif

    @endforeach

    </tbody>
</table>
Sinnbeck's avatar

@Josadec you don't add file extension to view code. Also make sure the actual file has blade in the name

view('exports.excel.reportperanswer', $data);

And file should be named reportperanswer.blade.php

Josadec's avatar

@Sinnbeck This file you need look? Livewire component

<?php

namespace App\Http\Livewire\Examsreports;

use Livewire\Component;

class FormExamsReports extends Component
{

    public function render()
    {
        return view('livewire.examsreports.form-exams-reports');
    }
}

View Livewire component

<div>
    <div class="container">
        <div class="px-10">
            <form action="" class="w-full max-w-lg" >

                <div class="flex flex-wrap -mx-3 mb-6">
                    <div class="w-full md:w-1/2 px-3 mb-6 md:mb-0">
                        <div class="grid grid-cols-1 divide-y">
                            <div class="py-5">
                               
                            </div>
                            <div class="py-5">
                                <label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="">De examen: </label>
                                    <x-input wire:model="fromExam" type="number" class="w-100 w-full" placeholder="Solo numeros" /> 
                                    {{-- @error()
                                        <div class="">{{ $message }}</div>
                                    @enderror --}}
                                <label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="">A examen:</label> 
                                    <x-input wire:model="toExam" type="number" class="w-full" placeholder="Solo numeros" />
                            </div>
                           {{--  <div class="py-5">
                                <x-label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for=""> De fecha:</x-label> 
                                <x-input type="date" class="min-w-full" /> 
                                <label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for=""> A fecha:</label> 
                                <x-input type="date" class="w-full" />
                            </div> --}}
                            <div class="py-5">
                                <a href="{{ route("reportExams") }}">
                                    <x-danger-button >
                                        Ver Reporte &rarr;  <i class="far fa-clipboard"></i>
                                    </x-danger-button>
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </form>     
        </div>
    </div>
   
</div>
Sinnbeck's avatar

@Josadec in the AnswersReport class you had this

return view('exports.excel.reportperanswer.php',$data); 
Josadec's avatar

@Sinnbeck Yes is this file "reportperanswer.blade.php"

<table>
    <thead>
    <tr>
        <th>#</th>
        <th>Pregunta</th>
        <th>Siempre</th>
        <th>Casi Siempre</th>
        <th>Algunas veces</th>
        <th>Casi nunca</th>Tyler
        <th>Nunca</th>
    </tr>
    </thead>
    <tbody>
    @php
        $preQuestion=null;
    @endphp
    
     @foreach($answers as $answer)
         @if($preQuestion!=$answer->question_id)
             @php $preQuestion=$answer->question_id; @endphp
             <tr>
                 <td>{{ $answer->question_id }}</td>
                 <td>{{ $answer->question_name."?" }}</td>
                 <td>{{ $preguntas['Siempre'][$answer->question_id]??0}}</td>
                 <td>{{ $preguntas['Casisiempre'][$answer->question_id]??0}}</td>
                 <td>{{ $preguntas['Algunasveces'][$answer->question_id]??0}}</td>
                 <td>{{ $preguntas['Casinunca'][$answer->question_id]??0}}</td>
                 <td>{{ $preguntas['Nunca'][$answer->question_id]??0}}</td>
             </tr>
        @endif

    @endforeach

    </tbody>
</table>
Snapey's avatar
Snapey
Best Answer
Level 122

@Josadec

this

return view('exports.excel.reportperanswer.php',$data);

change to

return view('exports.excel.reportperanswer',$data);
1 like

Please or to participate in this conversation.