0

For the first time, I am working on userfrosting, it is based on MVC. So I know how the things are working but my issue is now, I want to call the one of the model to find the particular userid ie. Employee::find(1)

I want to get the username for the particular id, as I am running a for loop to I will be getting different id.

How can I call the model in my template twig?

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
  • pass the object to twig and call the appropiate getter – DarkBee Aug 17 '16 at 16:12
  • I don't completely understand your question. Are you trying to work with just one particular `Employee` in your template, or a whole collection of `Employee`s? – alexw Aug 17 '16 at 16:39
  • suppose , I am querying select * from user and I am getting 5 rows in an array , so using for loop I am showing the data in table format and getting the userid which is related to employee table , so I want to use Employee::find(1) in template – user2982142 Aug 17 '16 at 17:23
  • What code you have now, how you render the template? – DarkBee Aug 18 '16 at 06:36
  • It sounds like you want to load the related user *along with each employee* in your controller, then pass that whole collection to your template. If each `Employee` has exactly one `User` associated with it, then your Employee model needs a `hasOne` relationship. See https://laravel.com/docs/5.2/eloquent-relationships#one-to-one – alexw Aug 18 '16 at 21:25
  • Please edit your question explain *exactly* what you want to do, and I can try to write up a complete answer. – alexw Aug 18 '16 at 21:27

0 Answers0