Structuring code logic for events on laravel controller The code below will store a base64 image on another website and create an event to display the image on a Vue page in real time. It works fine and all.
My question is, is this a good way of doing it or there's a better way to structure the code? I've thought about placing the logic in a listener but it doesn't seem that I need to use one. For queues, I'll add them later on.
Controller
public function store(Request $request)
{
    $base64 = $request-&gt;image;
    $image = str_replace('data:image/png;base64,', '', $base64);
    $imageName = 'draw'.time().'.png';
    $response = $this-&gt;guzzleClient()-&gt;post(config('archiving.api_postBase64_file'),
        [  
            'multipart' =&gt; [
                [
                    'name' =&gt; 'file',
                    'contents' =&gt; $image
                ],
                [
                    'name' =&gt; 'file_name',
                    'contents' =&gt; $imageName
                ],
                [
                    'name' =&gt; 'file_folder',
                    'contents' =&gt; 'drawings'
                ],
            ],
        ]
    );
    if($response-&gt;getStatusCode() &gt;= 500){
        return response($response-&gt;getBody(), $response-&gt;getStatusCode());
    }else{
        $drawing = Drawing::create([
            'user_id'=&gt;Auth::id(),
            'file_name'=&gt;$imageName,
        ]);
        event(new NewDrawing($drawing));
        return response('Drawing created!',200);
    }
}

NewDrawing Event
class NewDrawing implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $drawing;

    public function __construct(Drawing $drawing)
    {
        $this-&gt;drawing = $drawing;
    }
    public function broadcastOn()
    {
        return new Channel('channel-drawing');
    }
 }

Frontend (Vue)
&lt;script&gt;
export default {
    data(){
        return{
            images:'',
        }
    },
    methods:{
        listen() {
            Echo.channel('channel-drawing')
            .listen('NewDrawing', res =&gt; {
                this.images.push(res.drawing);
            })  
        }
    },
    mounted() {
        this.listen()
    }
}
&lt;/script&gt;
I'm mostly a back-end guy who fusses his way through front end code. Here's my advice:

Keep the controller code as close as possible to handling the response only. Delegate the creation of objects to their own classes. Think of the S in SOLID - Single Responsibility.
public function store(Request $request)
{
    $image = new ImageMeta($base64);
    $archiver = new ImageArchiver($image);
    $response = $archiver-&gt;post();

    if($response-&gt;getStatusCode() &gt;= 500){
        return response($response-&gt;getBody(), $response-&gt;getStatusCode());
    }else{
        $drawing = Drawing::create([
            'user_id'=&gt;Auth::id(),
            'file_name'=&gt;$imageName,
        ]);
        //There's a few different ways to look at this which might be part of a larger conversation, 
        // so I won't touch this part yet. But is this something specific to drawings? Or is the broadcast
        // of model creation something that will happen for lots of different models? Regardless, I would 
        // change the name from NewDrawing to something like DrawingCreationBroadcast, or something like that
        // NewDrawing gets confusing since its too close to new Drawing();
        event(new NewDrawing($drawing));
        return response('Drawing created!',200);
    }
 }



ImageMeta class
    /** For all classes assume property declarations, and getters are included. 
    * Lean toward immutable classes where possible, so don't include setters 
    * unless it becomes necessary. Code re-use != object instance re-use.
    **/

    class ImageMeta {
        public function __construct($base64) {
            $this-&gt;image = str_replace('data:image/png;base64,', '', $base64);
            $this-&gt;imageName = 'draw'.time().'.png';
        }
    }

ImageArchiver class
    class ImageArchiver {
        private $config;
        
        public function __construct(ImageMeta $image) {
            $this-&gt;image = $image;
            $this-&gt;makeConfig();
        }
        
        private function makeConfig() {
            $this-&gt;config = [  
                'multipart' =&gt; [
                    [
                        'name' =&gt; 'file',
                        'contents' =&gt; $image-&gt;getImage()
                    ],
                    [
                        'name' =&gt; 'file_name',
                        'contents' =&gt; $imageName-&gt;getName()
                    ],
                    [
                        'name' =&gt; 'file_folder',
                        'contents' =&gt; 'drawings'
                    ],
                ],
            ]
        }
        
        //use type hinting here. Off the top of my head I don't know the parent class of guzzleClient
        public function archive($guzzleClient) {
            return $guzzleClient-&gt;post($this-&gt;config);
        }

    }