mardi 29 octobre 2019

Get user ID while login from the LoginController.php laravel

I want to get user id immediately after the user has logged in. I have tried getting the user id using request but its not working. It prints the following error:

"Too few arguments to function App\Http\Controllers\Auth\LoginController::redirectTo(), 0 passed in C:\Users\owden\Documents\donation_system\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RedirectsUsers.php on line 15 and exactly 2 expected"

Below is my LoginController.php.

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;

use Illuminate\Foundation\Auth\AuthenticatesUsers;

use Illuminate\Support\Facades\Auth;

use Illuminate\Http\Request;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    protected function redirectTo(Request $request, $id)
    {
        if(Auth::user()->usertype == 'admin')
        {
            return 'dashboard';
        }
        elseif(Auth::user()->usertype == 'organization') {
            $user = User::find($id);
            return redirect ('/profile/{'.$id.'}');
        }else{
            return 'approval';
        }
    }
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}

And the routes:

Route::get('/profile', 'ProfilesController@index')->name('profile.show');
Route::get('/profile/{user}/edit', 'ProfilesController@edit')->name('profile.edit');
Route::patch('/profile/{user}', 'ProfilesController@update')->name('profile.update');


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire