Laravel:路由中的功能是什么?

问题描述 投票:0回答:1

谁能说出Laravel和其他人的文档为什么在返回/执行某些操作的路由中显示函数?您可以在什么情况下使用它?

例如,我尝试找出Molly Connect。

enter image description here

这里是来自https://github.com/mollie/laravel-mollie/blob/master/docs/mollie_connect.md的相应代码

Route::get('login', function () {
    return Socialite::with('mollie')
        ->scopes(['profiles.read']) // Additional permission: profiles.read
        ->redirect();
});

Route::get('login_callback', function () {
    $user = Socialite::with('mollie')->user();

    Mollie::api()->setAccessToken($user->token);

    return Mollie::api()->profiles()->page(); // Retrieve payment profiles available on the obtained Mollie account
});
laravel routing
1个回答
1
投票

这只是一个快捷方式,以避免必须创建单独的控制器文件并间接引用那些功能。从功能上讲,您的示例与执行此操作没有什么不同:

Route::get('login_callback', 'LoginController@callback')

然后,LoginController.php

class LoginController
{
    public function callback()
    {
        $user = Socialite::with('mollie')->user();
        Mollie::api()->setAccessToken($user->token);
        return Mollie::api()->profiles()->page();
    }
}

请参见here

© www.soinside.com 2019 - 2024. All rights reserved.