Yaluu Prasad
Yaluu Prasad

Reputation: 11

Too few arguments to function Illuminate\Routing\Router::group(), 1 passed in C:\xampp\htdocs\...php on the line 261 and exactly 2 expected

My Route is this

I tried using Guard method authentication and could not resolve it please help!! what could be the reason for these errors? If there is no specified content then please let me know.


Route::group(['middleware' => 'auth:admin',function(){
    Route::get('/dashboard', [AdminController::class, 'dashboard']);

}]);

here is the link where you can see through image My error image

My AdminController if needed

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator;
use App\Models\admin;
use Session;
use Auth;

class AdminController extends Controller
{
    public function index(){
        return view('admin.login');
    }

    public function makeLogin(Request $request){
        $validator = Validator::make($request->all(), [
            'username' => 'required',
            'password' => 'required'
        ]);
        if($validator -> fails()){
            return back()
                    -> withErrors($validator)
                    -> withInput();
        }

        $data = array(
            'username' => $request->username,
            'password' => $request->password,
        );
        
        if(Auth::guard('admin')->attempt($data)){
            return redirect('dashboard');
        }else{
            return back()->withErrors(['message' => 'invalid email or password']);
        }

    }

    public function dashboard(){
        return view('admin.dashboard');
    }
}

Upvotes: 1

Views: 3102

Answers (2)

Joseph
Joseph

Reputation: 6259

You just forgot and add the callback function inside the array it should be the second parameter like this

Route::group(['middleware' => 'auth:admin'],function(){
    Route::get('/dashboard', [AdminController::class, 'dashboard']);

});

you could also write it like this

Route::middleware(['middleware' => 'auth:admin'])->group(function() {
    Route::get('/dashboard', [AdminController::class, 'dashboard']);

});

Upvotes: 1

Josh Alecyan
Josh Alecyan

Reputation: 1176

You should set only middleware in array.

Route::group(['middleware' => 'auth:admin'],function(){
    Route::get('/dashboard', [AdminController::class, 'dashboard']);

});

Upvotes: 1

Related Questions