2

我有一个名为RankController.php. UsersController.php当我想分离一些方法时,我手动重命名。然后我选择将其重命名为RankController.php. 注意:我只改文件名,不改类名。这是控制器的代码。

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;
use App\User;
use App\Rank;
use App\Ban;

class RankController extends Controller
{

    // Constructor function
    public function __construct()
    {

        // Check if user is logged in
        $this->middleware('auth');
    }

    public function search(Request $request)
    {
        $this->validate($request, ['search' => 'required', ]);

        $users = User::select('id', 'name')->where([
            ['name', '!=', Auth()->user()->name],
            ['name', 'like', "%" . $request->input('search') . "%"], 
        ])->paginate(10);

        return view('rank.search')
            ->with('users', $users);
    }

}

这里是我调用控制器的地方:

{!! Form::open(['action' => ['RankController@search'], 'method' => 'POST']) !!}
    {{Form::text('search', '', ['placeholder' => 'Search a user'])}}
    {{Form::submit('Search', ['class' => 'btn btn-primary'])}}
{!! Form::close() !!}

注意:这是我收到错误的单个文件。这是错误:Action App\Http\Controllers\RankController@search 未定义。(查看:/var/www/htdocs/Proiect/resources/views/layouts/app.blade.php) (查看:/var/www/htdocs/Proiect/resources/views/layouts/app.blade.php)

我在其他 PC 上尝试代码,它会产生相同的错误。

4

2 回答 2

4

我觉得你必须更新路线"UsersController"并运行"composer dumpautoload

于 2018-09-25T07:36:53.477 回答
3

确保文件名和类名相同,然后尝试以下命令:

1)php artisan route:cache
2)php artisan route:clear
3)composer dumpautoload -o
于 2018-09-25T07:39:39.087 回答