How to resolve : ReflectionException in Route.php line 333: Method App\Http\Controllers\PerekamanController::show() does not exist" in Laravel 5.3?

放肆的年华 提交于 2019-12-12 04:27:15

问题


My proses.blade.php is like this :

<form method="POST" action="{{ url('/perekamans/proses') }}">
    {!! csrf_field() !!}
    ...
</form>

My routes\web.php is like this :

Route::resource('perekamans', 'PerekamanController');

Route::get('perekamans/proses', ['uses' => 'PerekamanController@listdata']);

My PerekamanController is like this :

<?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');
    }
}

My show.blade.php is like this :

@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

I call from url like this : http://localhost/mysystem/public/perekaman/proses

There exist error like this :

Whoops, looks like something went wrong. 1/1 ReflectionException in Route.php line 333: Method App\Http\Controllers\PerekamanController::show() does not exist

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

It looks like my code is correct, but why it is still an error?

Is there any solution to solve my problem?

Update :

Sorry, I can not answer all your questions. every time I write a comment to answer questions with you, and then click the comment button, it can not. there exist message :
question eligible for bounty in 2 days
so you immediately provide any solution


回答1:


you make mistake at your route:

Route::get('perekamans/proses', ['uses' => 'PerekamanController@listdata']);

Route::resource('perekamans', 'PerekamanController');

Change the sequence become like that.

And one more thing at Laravel you can make it simpler.

Route::get('perekamans/proses', 'PerekamanController@listdata');

you don't need to use uses to set which controller it will use




回答2:


Your controller is missing all of the resource methods (index, create, store, show, etc..). You need all of the methods mentioned in the documentation in the "actions" column.

Its a good idea to use artisan to scaffold your controller when you plan on using resource controllers:

php artisan make:controller --resource PerekamanController 



回答3:


Add show() method in your PerekamanController. Your route seem to be strange and that might be not work well . So make sure that your Http Webserver Rewrite is open.

If you use Apache,open your mod_rewrite and try this code in your .htaccess file

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

If Nginx,try this in your config file

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

Hope this would help you



来源:https://stackoverflow.com/questions/41069673/how-to-resolve-reflectionexception-in-route-php-line-333-method-app-http-cont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!