I am learning laravel and trying to create a community with laravel. I stuck at some part and need to ask you guys.
Right now I am trying to displaying posts to reader.
This is what i accomplish so far
with this 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')->where('title', '=', $title)->first();
//Do we have this thread?
if(!$query)
{return Redirect::to('entry/suggest');}
//We have? so lets rock it!
$view->title = $query->title; //we get the title.
$thread_id = $query->id;
//getting posts.
$posts = DB::table('posts')->where('thread_id', '=', $thread_id)->get();
$view->posts = $posts;
return $view;
}
and the view is :
<div id="entrybox">
<h2>{{$title}}</h2>
@foreach($posts as $post)
<p class="entry"><span class="entrynumber">1</span><span class="entry_text">{{$post->post_entry}}</span></p>
<p align="right" class="edate"><span class="entry_user">{post_row.POST_USERNAME}</span> <span class="entry_date">{post_row.DATE}</span></p>
@endforeach
</div>
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.
Lets say $posts variable holds data of 10 posts for a thread *a post has thread_id , poster_userid, post, posted_date.
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.