class ShowProfile extends Controller
{
public function __invoke($id)
{
return view(‘user.profile‘, [‘user‘ => User::findOrFail($id)]);
}
}
Route::get(‘user/{id}‘, ‘ShowProfile‘);
PHP 中当尝试以调用函数的方式调用一个对象时,__invoke()
方法会被自动调用。
原文:https://www.cnblogs.com/sjhsszl/p/8794619.html