php - Get value from view -


I have two table users & amp; There are links between paragraph tables

Model:

  class articles eloquent {public static $ table = 'article'; Public function user () {back to $ this- & gt; Has_one ('user', 'id'); }   

and

  class user eloquence {public static $ table = 'user' extends; Public Work Article () {Return $ $-> Belong_to ('article', 'id_user'); }   

I have to get the value of the name directly from the user on paragraph view, but does not work with error

My Controller:

  Public function action_index () {$ article = paragraph :: order_by ('id') - & gt; Endorse (10); See Return: Creating ('article.index') - & gt; Together ('$ article', $ paragraph); }   

My view: @foreach ($ articles-> $ Arti results) & lt; Tr & gt; & Lt; TD & gt; {{$ Arti-> Id}} & lt; / TD & gt; & Lt; TD & gt; {{$ Arti-> Tag}} & lt; / TD & gt; & Lt; Td> {$ $ Arti-> User- & gt; Name}} & lt; / Td> & Lt; ------ Error & lt; Td> {{$ Arti-> Content}} & lt; / Td> & Lt; TD & gt; {{$ Arti-> Date}} & lt; / TD & gt; & Lt; TD & gt;

See below, some things are different for you ... < / Li>

  • article or user >)
  • The subject class of your relationship should have names of names (i.e. article or user
  • foreign names should be named relationship_id user_id
  • Add :: with to your query
  • When you see in your view, - & gt; Results The class article spreads eloquent {// 3: lowercase 'user' public function user () 1 // The article comes to the user

    : 4: class name 'user' // 5: The foreign key on the article table is user_id $ $ the-> corresponding_to ('user');}} // model / user.fp class user elaboration {// 3: lowercase plural 'Articles' Public Festivals Articles (): // 2: Many Articles of the User / 4: Class Name 'Article' Returns $ this- & gt; Has_many ('paragraph'); }} // Controller / articles.php class extends Article_Controller Base_Controller {public $ restful = true; Public function get_index () {// 6: curious loading of user relationship, with :: ('user') $ articles = Article :: with ('user') - & gt; Order_by ('id') - & gt; Paginate 10); See Return: Creating ('articles.index', Compact ('Articles')); }} // thoughts / article / index.blade.php // 7: $ article- & gt; Pageant results- foreach ($ article-> results as $ $ article) & lt; H1 & gt; {{$ Article- & gt; ; Title}} & lt; / H1> & Lt; P & gt; {{$ Article- & gt; User- & gt; Name}} & lt; / P & gt; @earncheck {{$ article- & gt; Link ()}}

  • Comments

    Popular posts from this blog

    excel vba - How to delete Solver(SOLVER.XLAM) code -

    github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

    ios - Replace text in UITextView run slowly -