I'm having troubles with something that I just can´t explain. I'm working with laravel and I just write a route for get method, no such a big deal, but for this route I'm calling a method called generatefile and laravel is calling my index method wich it doesn´t make sense. This is my code.
ReportController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\ReportTypes;
use App\Report;
use App\Hardware;
use App\Customer;
use App\User;
use App\ReportNotes;
use DB;
use PDF;
use Illuminate\Support\Carbon;
class ReportController extends Controller
{
public function index($type){
$data = new ReportTypes;
$datatype = $data->getData($type);
$hm = $datatype->report_type_includes_hardware ? true : false;
$customers = Customer::all();
$users = User::all();
$report = new Report;
$reports = $report->getData($type);
if($hm){
$models = Hardware::all();
return view('report/types/index',compact('datatype','hm','models','customers','users','reports'));
}
return view('report/types/index',compact('datatype','hm','reports','customers','users'));
}
public function generatefile(){
$data = ['title' => 'Welcome to HDTuto.com'];
$pdf = PDF::loadView('myPDF', $data);
return $pdf->download('hdtuto.pdf');
}
public function details($type, $folio){
$data = new ReportTypes;
$datatype = $data->getData($type);
$report_notes = new ReportNotes;
$type_id = DB::table('report_types')->where('report_type_serie','=',$type)->get()->first();
$report = DB::table('reports')->where([
['FK_report_type_id','=',$type_id->PK_report_type_id],
['report_folio','=',$folio]
])->first();
$notes = $report_notes->getData($report->PK_report_id);
return view('report/types/details',compact('datatype','notes','report'));
}
public function store(Request $request){
$report = new Report;
$data = new ReportTypes;
$report->FK_report_type_id = $request->RPType;
$report->report_folio = $data->nextFolio($request->RPType);
$report->FK_customer_id = $request->RPCustomer;
$report->FK_hardware_model_id = $request->RPHardware;
$report->FK_creator_user_id = $request->RPCreator;
$report->FK_responsable_user_id = $request->RPResp;
$report->FK_assistant1_user_id = $request->RPAssist;
$report->FK_report_state_id = 1;
$report->report_issue = $request->RPIssue;
$report->report_description_issue = $request->RPDescIssue;
$report->report_created_at = Carbon::now();
$report->report_attended_at = Carbon::now();
$report->report_updated_at = Carbon::now();
$report->report_finished_at = Carbon::now();
$report->save();
$data->incrementFolio($request->RPType);
return redirect()->route('reports',$request->RPTypeSerie);
}
}
My Route
Route::get('reports/getfile','ReportController@getfile')->name('report.generatefile');
Route::get('reports/{type}','ReportController@index')->name('reports');
And when I try to access this route, I get this:
I get the error in the index method, but I'm not calling it.
Can anyone please explain me why is this happening?