如何解决:Route.php 行 333 中的 ReflectionException:Laravel 5.3 中的方法 App\Http\Controllers\PerekamanController::show() 不存在”?
How to resolve : ReflectionException in Route.php line 333: Method App\Http\Controllers\PerekamanController::show() does not exist" in Laravel 5.3?
我的proses.blade.php是这样的:
<form method="POST" action="{{ url('/perekamans/proses') }}">
{!! csrf_field() !!}
...
</form>
我的routes\web.php是这样的:
Route::resource('perekamans', 'PerekamanController');
Route::get('perekamans/proses', ['uses' => 'PerekamanController@listdata']);
我的 PerekamanController 是这样的:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PerekamanController extends Controller
{
public function index(Request $request)
{
return view('perekamans.index');
}
public function listData()
{
return view('perekamans.show');
}
}
我的show.blade.php是这样的:
@extends('layouts.app')
@section('content')
<section class="content-header">
<h1 class="pull-left">PEREKAMAN DATA</h1>
</section>
<div class="content">
<div class="clearfix"></div>
@include('flash::message')
<div class="clearfix"></div>
<div class="box box-primary">
<div class="box-body">
@include('perekamans.table')
</div>
</div>
</div>
@endsection
我从 url 打电话是这样的:http://localhost/mysystem/public/perekaman/proses
存在这样的错误:
糟糕,好像出了点问题。
Route.php 行 333 中的 1/1 ReflectionException:方法 App\Http\Controllers\PerekamanController::show() 不存在
in Route.php line 333
at ReflectionMethod->__construct('App\Http\Controllers\PerekamanController', 'show') in Route.php line 333
at Route->signatureParameters('Illuminate\Database\Eloquent\Model') in Router.php line 789
我的代码看起来是正确的,为什么还是报错?
有什么办法可以解决我的问题吗?
更新:
对不起,我不能回答你所有的问题。每次我写评论跟大家回答问题,然后点击评论按钮,就不行了。存在消息:
2 天内有资格获得赏金的问题
所以你立即提供任何解决方案
您的控制器缺少所有资源方法(索引、创建、存储、显示等)。您需要 "actions" 列中的所有方法 mentioned in the documentation。
当您计划使用资源控制器时,最好使用 artisan 搭建您的控制器:
php artisan make:controller --resource PerekamanController
在您的 PerekamanController 中添加 show() 方法。
您的路线似乎很奇怪,可能效果不佳。因此请确保您的 Http Webserver Rewrite 已打开。
如果您使用 Apache,请打开您的 mod_rewrite 并在您的 .htaccess 文件中尝试此代码
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
如果是 Nginx,请在你的配置文件中尝试这个
location / {
try_files $uri $uri/ /index.php?$query_string;
}
希望对您有所帮助
你走错路线了:
Route::get('perekamans/proses', ['uses' => 'PerekamanController@listdata']);
Route::resource('perekamans', 'PerekamanController');
把顺序改成那样。
Laravel 还有一件事你可以让它更简单。
Route::get('perekamans/proses', 'PerekamanController@listdata');
您不需要使用 uses
来设置它将使用哪个控制器
我的proses.blade.php是这样的:
<form method="POST" action="{{ url('/perekamans/proses') }}">
{!! csrf_field() !!}
...
</form>
我的routes\web.php是这样的:
Route::resource('perekamans', 'PerekamanController');
Route::get('perekamans/proses', ['uses' => 'PerekamanController@listdata']);
我的 PerekamanController 是这样的:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PerekamanController extends Controller
{
public function index(Request $request)
{
return view('perekamans.index');
}
public function listData()
{
return view('perekamans.show');
}
}
我的show.blade.php是这样的:
@extends('layouts.app')
@section('content')
<section class="content-header">
<h1 class="pull-left">PEREKAMAN DATA</h1>
</section>
<div class="content">
<div class="clearfix"></div>
@include('flash::message')
<div class="clearfix"></div>
<div class="box box-primary">
<div class="box-body">
@include('perekamans.table')
</div>
</div>
</div>
@endsection
我从 url 打电话是这样的:http://localhost/mysystem/public/perekaman/proses
存在这样的错误:
糟糕,好像出了点问题。 Route.php 行 333 中的 1/1 ReflectionException:方法 App\Http\Controllers\PerekamanController::show() 不存在
in Route.php line 333
at ReflectionMethod->__construct('App\Http\Controllers\PerekamanController', 'show') in Route.php line 333
at Route->signatureParameters('Illuminate\Database\Eloquent\Model') in Router.php line 789
我的代码看起来是正确的,为什么还是报错?
有什么办法可以解决我的问题吗?
更新:
对不起,我不能回答你所有的问题。每次我写评论跟大家回答问题,然后点击评论按钮,就不行了。存在消息:
2 天内有资格获得赏金的问题
所以你立即提供任何解决方案
您的控制器缺少所有资源方法(索引、创建、存储、显示等)。您需要 "actions" 列中的所有方法 mentioned in the documentation。
当您计划使用资源控制器时,最好使用 artisan 搭建您的控制器:
php artisan make:controller --resource PerekamanController
在您的 PerekamanController 中添加 show() 方法。 您的路线似乎很奇怪,可能效果不佳。因此请确保您的 Http Webserver Rewrite 已打开。
如果您使用 Apache,请打开您的 mod_rewrite 并在您的 .htaccess 文件中尝试此代码
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
如果是 Nginx,请在你的配置文件中尝试这个
location / {
try_files $uri $uri/ /index.php?$query_string;
}
希望对您有所帮助
你走错路线了:
Route::get('perekamans/proses', ['uses' => 'PerekamanController@listdata']);
Route::resource('perekamans', 'PerekamanController');
把顺序改成那样。
Laravel 还有一件事你可以让它更简单。
Route::get('perekamans/proses', 'PerekamanController@listdata');
您不需要使用 uses
来设置它将使用哪个控制器