duanlong4890 2018-10-20 00:44
浏览 224
已采纳

Laravel调用的方法与Route函数中指定的方法不同

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:

enter image description here

I get the error in the index method, but I'm not calling it.

Can anyone please explain me why is this happening?

  • 写回答

3条回答 默认 最新

  • dougupang0901 2018-10-20 01:01
    关注

    Put your route before to index route and try. You can to check this question: Laravel Route issues with Route order in web.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化