我有一个名为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 上尝试代码,它会产生相同的错误。