Support the ongoing development of Laravel.io →
IOC Architecture

Sometimes when I'm making a request I have a common piece of data, so I will set it in the BaseController like so:

$this->data['cities'] = Cities::get();

However the controllers $this is not available in models or filters. Is it a good idea to create some kind of Data service for this with a couple methods for set and `get?

Data::set('cities', Cities::get());
Data::get('cities');

This way I can just access my data from anywhere.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

websanova websanova Joined 8 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.