2

I have an admin page where I would like to display information about my posts and the campaigns in the system on a single page. There is no relation between campaigns and posts. They are two different aspects of the application .

Right now I have a page where I can display data related to posts and another page where I display data related to campaigns, however this is not what I would like to have.

Any help would be well appreciated.

1 Answer 1

2

Create two separate repositories for getting data from these sources - perhaps GetPostRepository and GetCampaignRepository.

Within these, write separate functions for getting the relevant data you want. Perhaps getActiveCampaigns() in the GetCampaignRepository and getActivePosts in the GetPostsRepository.

Then, in the same controller, inject these new repositories. (Jeffery Way on Dependency Injection: http://net.tutsplus.com/tutorials/php/dependency-injection-huh/)

You can now run these functions, get your data and send them to your view. A contrived example below:

function showPostsandCampaigns()
{
    $campaign = $this->campaign->getActiveCampaigns();
    $posts = $this->posts->getActivePosts();

    return View::make('view')->with('campaign' , $campaign)->with('posts' , $posts);
} 
Sign up to request clarification or add additional context in comments.

1 Comment

Hi James .. thank you for your reply.. much appreciated. however i have another doubt please - How do i refer to my Post model within the GetPostRepository .. sorry for the stupid question - i am still learning laravel .. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.