Support the ongoing development of Laravel.io →
Configuration Views

Hi I am still learning and would just like to ask how I would refactor the following?

    $properties = Property::latest()->take(18)->get();
    $locations = Location::pluck('name','id')->all();
    $types = Type::pluck('name','id')->all();

I don't want to have to include those three lines in every function of my controller for different views, how to I go about setting it up once and then using it where I see fit?

Thanks in advance for any answers.

Last updated 3 years ago.
0

You could create a base controller and extend each controller from it or you could use a ServiceProvier to share your data globally: https://laravel.com/docs/5.4/views#passing-data-to-views

0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.