0

I have simple function in one of my controller (members):

function action_data($array) { 
    $datamembre = DB::table('members')->where('id', '=', $id)->first(); 
    return $datamembre; 
}

I want use it in the view of another controller, I do this in my template:

 $datamembers = Controller::call('members@data', array($members_id));

Is there any better or proper way to do it?

2 Answers 2

4

The best would be to put it into a Member model IMO.

Sign up to request clarification or add additional context in comments.

1 Comment

This. It looks like data logic so it belongs in a model. Provide it to your view using a composer. You should not have any calls to controllers, models, et al.. in your view.
0

Use view composer http://laravel.com/docs/views#view-composers

View::composer(array('home', 'profile'), function($view)
{
    //
});

update

You can put the method in BaseController, all controllers extend it, so you could get this method in any controller/view. And make it static.

// in BaseController.php (L4) or Base.php (L3)

static public function action_data($array) { 
    $datamembre = DB::table('members')->where('id', '=', $id)->first(); 
    return $datamembre; 
}

In the view

BaseController::action_data($array); //L4

Base_Cotroller::action_data($array); //L3

Hope it works. Haven't tested it.

2 Comments

Thanks but composer is for view, i dont want include any view i want to use my function for display each username.
Updated. If it's want you wanted accept it as the correct answer so others can use it.

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.