@walkerstech

Слишком мало аргументов для работы?

Получил ошибку:
Too few arguments to function App\Http\Controllers\UserController::LoginWithVk(), 0 passed in /localhost/app/Http/Controllers/UserController.php on line 25 and exactly 1 expected

web.php
Route::get('/login/{type}', [App\Http\Controllers\UserController::class, 'login']);

UserController.php
<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use romanzipp\Twitch\Enums\EventSubType;
use romanzipp\Twitch\Twitch;
use romanzipp\Twitch\Enums\GrantType;

class UserController extends Controller
{
    public function login($type){
        switch ($type) {
            case "twitch":
                $this->LoginWithTwitch();
                break;
            case "youtube":
                $this->LoginWithYouTube();
                break;
            case "vk":
                $this->LoginWithVk();
                break;

            default:
                return redirect()->route('landing');
                break;
        }
    }
    public function LoginWithVk(Request $request){
        if (empty($request->get('code'))) {
            return $this->VKRedirectToLogin();
        } else {
            $token = $this->VKGetAuthToken($request->get('code'));
            if (isset($token['access_token'])) {
                $userInfo = $this->VKGetUserInfo($token);
                if (isset($userInfo['response'][0]['id'])) {
                    $userInfo = $userInfo['response'][0];
                    $u = User::where('user_vk', $userInfo["id"])->first();
                    if(!($u)){
                        $data = ['user_email' => '', 'user_login' => 'vkid'.$userInfo["id"], 'user_login_show' => $userInfo['first_name'] . " " . $userInfo['last_name'], 'user_domain' => 'vkid'.$userInfo["id"], 'user_vk' => $userInfo["id"],
                            'user_group' => 1, 	'user_wallets' => '{"qiwi":"null","webmoney":"null","yamoney":"null","bank":"null","paypal":null}', 'user_wallets_pay' => 0,
                            'user_paypal' => '{"clientid":"","secret":"","email":"","on":"0"}', 'user_stream_status' => 0, 'user_avatar' => $userInfo["photo_big"], 'user_donate_page' => '{"min_sum":"1","rec_sum":"50","text":"","fuck_filter":"0","fuck_name_filter":"0","fuck_words":"","bg_color":"#e0e0e0","bg_type":"1","bg_size":"auto","bg_image":"","bg_image_name":"","bg_repeat":"no-repeat","bg_position":"center","bg_header_type":"1","bg_header_image":"","bg_header_size":"auto","bg_header_repeat":"no-repeat","bg_header_position":"center","bg_header_color":"#f2f2f2","text_header_color":"#000000","btn_color":"#ff5400","btn_text_color":"#ffffff","comission":"0"}',
                            'user_reg_time' => now(), 'user_reg_ip' => $_SERVER['REMOTE_ADDR']];
                        $user = User::create($data);
                        $remember = true;
                        Auth::login($user, $remember);
                        return redirect()->route('dashboard');
                    } else {
                        $user = User::where('user_vk', $userInfo["id"])->first();
                        $user->update(['user_last_login_time' => now(), 'user_last_ip' => $_SERVER['REMOTE_ADDR']]);
                        $remember = true;
                        Auth::login($user, $remember);
                        return redirect()->route('dashboard');
                    }
                }
            }
        }
    }

    /*VKAuth*/
    private function VKRedirectToLogin()
    {
        $url = 'http://oauth.vk.com/authorize';
        $params = array(
            'client_id' => config('services.vkontakte.client_id'),
            'redirect_uri' => config('services.vkontakte.redirect'),
            'response_type' => 'code'
        );
        return redirect($url . '?' . urldecode(http_build_query($params)));
    }

    private function VKGetAuthToken($code)
    {
        $params = [
            'client_id' => config('services.vkontakte.client_id'),
            'client_secret' => config('services.vkontakte.client_secret'),
            'code' => $code,
            'redirect_uri' => config('services.vkontakte.redirect'),
        ];
        return json_decode($this->get_curl('https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params))), true);
    }

    private function VKGetUserInfo($token)
    {
        $params = [
            'uids' => $token['user_id'],
            'fields' => 'uid,first_name,last_name,photo_big,email',
            'access_token' => $token['access_token'],
            'v' => '5.103'
        ];
        return $userInfo = json_decode($this->get_curl('https://api.vk.com/method/users.get' . '?' . urldecode(http_build_query($params))), true);
    }

    function get_curl($url)
    {
        if (function_exists('curl_init')) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            $output = curl_exec($ch);
            echo curl_error($ch);
            curl_close($ch);
            return $output;
        } else {
            return file_get_contents($url);
        }
    }
    /*EndVKAuth*/
}
  • Вопрос задан
  • 1539 просмотров
Решения вопроса 1
part_os
@part_os
Сложное в простом
public function login(Request $request, $type){
первым идёт объект реквеста
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы