This is not real-time but the logic and code to do what you want to do.
Well when the user first submits the article the default in the database should be set to inactive. You already have this. In you posts table you will need a field for status that is either published or unpublished. The same thing you probably did with status on active or inactive for admin.
Next, just do a query that grabs the unpublished article like so: Then you can use javascript to grab data in real-time from the db. Also, wouldn't a cron job work to grab what you need. http://code.tutsplus.com/tutorials/managing-cron-jobs-with-php--net-19428
public function get_live_posts($limit)
{
$data = array();
$this->db->limit($limit);
$this->db->where('status', 'published');
$this->db->order_by('pub_date', 'desc');
$query = $this->db->get('posts');
if ($query->num_rows() > 0)
{
foreach ($query->result_array() as $row)
{
$data[] = $row;
}
}
$query->free_result();
return $data;
}
Hey guys! Thanks for your replies :).
I managed to make a simple working thing, using Laravel and AngularJS, that actually does what I need. It runs the get request to the server in a set interval, but I can almost for sure say that this is not optimal, and that it might be sending too many request to the server?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community