Note that there are some explanatory texts on larger screens.

plurals
  1. POHandle arrays in laravel
    primarykey
    data
    text
    <p>I am learning laravel and trying to create a community with laravel. I stuck at some part and need to ask you guys.</p> <p>Right now I am trying to displaying posts to reader.</p> <p>This is what i accomplish so far <img src="https://i.stack.imgur.com/RZmY9.jpg" alt="http://i.imgur.com/lc5gX.jpg"></p> <p>with this code : </p> <pre><code>public $restful = true; public function get_index($title = '') { //Do we have an arguement? if(empty($title)) {return Redirect::to('dashboard');} $view = View::make('entry'); $query = DB::table('threads')-&gt;where('title', '=', $title)-&gt;first(); //Do we have this thread? if(!$query) {return Redirect::to('entry/suggest');} //We have? so lets rock it! $view-&gt;title = $query-&gt;title; //we get the title. $thread_id = $query-&gt;id; //getting posts. $posts = DB::table('posts')-&gt;where('thread_id', '=', $thread_id)-&gt;get(); $view-&gt;posts = $posts; return $view; } </code></pre> <p>and the view is : </p> <pre><code>&lt;div id="entrybox"&gt; &lt;h2&gt;{{$title}}&lt;/h2&gt; @foreach($posts as $post) &lt;p class="entry"&gt;&lt;span class="entrynumber"&gt;1&lt;/span&gt;&lt;span class="entry_text"&gt;{{$post-&gt;post_entry}}&lt;/span&gt;&lt;/p&gt; &lt;p align="right" class="edate"&gt;&lt;span class="entry_user"&gt;{post_row.POST_USERNAME}&lt;/span&gt; &lt;span class="entry_date"&gt;{post_row.DATE}&lt;/span&gt;&lt;/p&gt; @endforeach &lt;/div&gt; </code></pre> <p>But the hard part(for me) is integrate posts with poster's username or other user info like e-mail for moderate privileges. However hey are in 'users' table.</p> <p>Lets say $posts variable holds data of 10 posts for a thread *a post has thread_id , poster_userid, post, posted_date.</p> <p>How can i grab username from 'users' table and send it to my view? I am sure i need to use foreach after selecting posts from database I just dont know how to handle arrays in foreach.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload