Support the ongoing development of Laravel.io →
Requests Views Architecture

Sorry for the noob question, I'm using an Instagram API library all across my website, every view uses it.. but in every controller function, I need to have the exact same connection function returning the instagram object, then passing them to the views...

Is there a possibility of creating the object once, and it would be available across all the pages? (Or at least more easily referenced or instantiated?

Another quick question: If I create the instagram Model, without having any tables named instagram on the database, is there a problem? Is it against any good practices?

Last updated 3 years ago.
0

Take a look at this page and familiarize yourself with the Laravel IoC container: http://laravel.com/docs/4.2/ioc What you're describing is a singleton, so read that section carefully. You could then reference it from the application facade or using dependency injection in a controller constructor.

When you create an Eloquent model it will look for the plural form of the class name so if the class is named 'Instagram' then it will look for a table named 'instagrams' in your database. I don't know off the top of my head if it will throw an error if the model class isn't being used in any other code. You can specify the name of the table by adding a protected property named 'table' (see http://laravel.com/docs/4.2/eloquent#basic-usage).

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

raphadko raphadko Joined 13 Jul 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.