Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Current User Bundle Laravel Package

dyvelop/current-user-bundle

View on GitHub
Deep Wiki
Context7

Build Status

Dyvelop Current User Bundle

Symfony bundle to fetch the user which is currently logged in.

Installation

Step 1: Download

Download via Composer

composer require dyvelop/current-user-bundle

Step 2: Enable Bundle

Enable the Bundle in the app/AppKernel.php file in your Symfony project:

// File: app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Dyvelop\CurrentUserBundle\DyvelopCurrentUserBundle(),
        );
        
        return $bundles;
    }
}

Usage

Current User Provider

Mainly this bundle implements a service named dyvelop.current_user.provider which provides the current user:

// fetch current user (the result is NULL when no one is logged in)
$user = $this->container->get('dyvelop.current_user.provider')->getUser();

You may use the CurrentUserAware interface and CurrentUserTrait helper to inject it into any other service.

Doctrine Annotation

Secondly, this bundle provides a Doctrine Annotation and Driver to inject the Current User into an entity via lifecycle callbacks:

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Dyvelop\CurrentUserBundle\Annotation as Dyvelop;

class Article
{
    /**
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=true)
     * @Dyvelop\CurrentUser(prePersist=true)
     */
    protected $author;
}

In this example the current user will be set automatically as author of an article before persisting it to the database.

Currently, only the prePersist and preUpdate lifecycle callbacks are implemented. Feel free to contribute some more ;)

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky