Skip to content

Instantly share code, notes, and snippets.

@franzliedke
Last active August 29, 2015 14:04
Show Gist options
  • Save franzliedke/37f35777956516cb9149 to your computer and use it in GitHub Desktop.
Save franzliedke/37f35777956516cb9149 to your computer and use it in GitHub Desktop.
FluxBB Eloquent models

FluxBB Eloquent Models

Some sample models that show how to access FluxBB data through simple Eloquent magic.

Usage

Retrieve recent posts (defaults to 10)

Post::recent()->get();

Retrieve 20 recent posts

Post::recent(20)->get();
<?php
class Group extends Eloquent
{
protected $table = 'groups';
public function users()
{
return $this->hasMany('User', 'group_id');
}
}
<?php
class Post extends Eloquent
{
protected $table = 'posts';
public function topic()
{
return $this->belongsTo('Topic', 'topic_id');
}
public function scopeRecent($query, $limit = 10)
{
return $query->orderBy('posted', 'DESC')->take($limit);
}
}
<?php
class Topic extends Eloquent
{
protected $table = 'topics';
public function posts()
{
return $this->hasMany('Post', 'topic_id');
}
public function firstPost()
{
return $this->belongsTo('Post', 'first_post_id');
}
public function lastPost()
{
return $this->belongsTo('Post', 'last_post_id');
}
}
<?php
class User extends Eloquent
{
protected $table = 'users';
public function group()
{
return $this->belongsTo('Group', 'group_id');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment