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

File Bundle Laravel Package

bengor/file-bundle

View on GitHub
Deep Wiki
Context7

Upload as relation to other entity

// src/AppBundle/Entity/User.php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * [@ORM](https://github.com/ORM)\Entity
 * [@ORM](https://github.com/ORM)\Table(name="user")
 */
class User
{
    /**
     * [@ORM](https://github.com/ORM)\Id()
     * [@ORM](https://github.com/ORM)\GeneratedValue(strategy="UUID")
     * [@ORM](https://github.com/ORM)\Column(name="id", type="string", length=36)
     */
    private $id;

    /**
     * [@ORM](https://github.com/ORM)\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * [@ORM](https://github.com/ORM)\OneToOne(targetEntity="AppBundle\Entity\File", cascade={"persist"})
     */
    private $file;

    // Getters and Setters
}
// src/AppBundle/Entity/File.php

namespace AppBundle\Entity;

use BenGorFile\File\Domain\Model\File as BaseFile;
use Doctrine\ORM\Mapping as ORM;

/**
 * [@ORM](https://github.com/ORM)\Entity
 * [@ORM](https://github.com/ORM)\Table(name="bengor_file")
 */
class File extends BaseFile
{
}
// src/AppBundle/Controller/DefaultController.php

namespace AppBundle\Controller;

use BenGorFile\FileBundle\Controller\UploadAction;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    use UploadAction;

    /**
     * [@Route](https://github.com/Route)("/user/new/", name="app_user_new")
     */
    public function createUserAction(Request $request)
    {
        $fileData = [];
        if ($request->getMethod() === 'POST') {
            $fileData = $this->uploadAction($request, $this->get('bengor_file.file.command_bus'), 'file');
            $file = $this->get('bengor_file.file.repository')->fileOfId(new FileId($fileData['id']));
            
            $user = new User();
            $user
                ->setName($request->request->get('name'))
                ->setFile($file);

            $manager = $this->getDoctrine()->getManager();
            $manager->persist($user);
            $manager->flush();
        }

        return $this->render('user/new.html.twig', $fileData);
    }
}
{# app/Resources/views/user/new.html.twig #}

{% extends 'base.html.twig' %}

{% block body %}
    {% if filename is defined %}
        <p>{{ filename }}</p>
    {% endif %}

    <form enctype="multipart/form-data" method="post" action="{{ path('app_user_new') }}">
        <input type="text" name="name"/>
        <input type="file" name="file"/>
        <input type="submit"/>
    </form>
{% endblock %}
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui