Categories

Thursday, December 26, 2024
#919814419350 therichposts@gmail.com
Laravel

How to use laravel Auth::user() id in query?

Laravel 7.2 routing with route group auth guard check with prefix

use laravel Auth::user() id in query

Hello to all, welcome to therichpost.com. In this post, I will tell you, How to use laravel Auth::user() id in query? Like I always say that laravel is the best Mvc php framework.

In this post, I will tell you to use laravel Auth::user() id in query and here are they:
$activated_up = User::where('id',Auth::user()->id)->get();

//or

User::find(Auth::user()->id);

  if you have any query related this post then please do ask

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

1 Comment

  • Route::group([‘middleware’ => [‘checkAuth’]], function () {

    Route::get(‘/’, function () {
    return redirect(‘/dashboard’);
    });
    Route::get(‘/logout’,’LoginController@logout’);
    });

    middleware

    //middleware

    namespace App\Http\Middleware;

    use Closure;
    use Session;
    use DB;

    class CheckAuth
    {
    /**
    * Handle an incoming request.
    *
    * @param \Illuminate\Http\Request $request
    * @param \Closure $next
    * @return mixed
    */
    public function handle($request, Closure $next)
    {
    $USER = Session::get(‘USER’);
    $ADMIN = Session::get(‘ADMIN’);
    if($ADMIN || $USER) {
    // $PDO = DB::connection()->getPdo();
    // getRole($PDO, $USER);
    return $next($request);
    } else {
    return redirect(‘/signin’);
    }
    }
    }

    //kernal

    protected $routeMiddleware = [

    /* Check Custom Auth */
    ‘checkAuth’ => \App\Http\Middleware\CheckAuth::class,

    ];

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.