I have 2 Models ( tables ) on my Laravel4.2 Web Application
Which is : _blog & _text
I'm still learning the process of managing data & logic between Controllers & Models with Laravel
On a my Blog Models, I got a function call listBlog , which is pass a parameter to have a dynamic querying for the _blog table.
But when comes to Text Models, do I need duplicate the listBlog function again to listText ?
It seems repeative for me & what if I got more than 5 tables that wanted to share the function ?
Below are my example codes for Blog Models also Text Models :
Blog :
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class Blog extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = '_blog';
public $timestamp = false;
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
public static function listBlog($nextID=0,$status='approved')
{
$query = Blog::where('status',$status);
$query = $query->orderBy('id','desc')->skip($nextID)->take(6);
return $query->get();
}
}
Text :
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class Text extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = '_text';
public $timestamp = false;
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
public static function listText($nextID=0,$status='approved')
{
$query = Text::where('status',$status);
$query = $query->orderBy('id','desc')->skip($nextID)->take(6);
return $query->get();
}
}
Because on Laravel Framework, I need create a new Model .php file Blog.php & Text.php to call eloquent method on controller eg : Blog::all(); or Text::listText(0,'rejected');
is there any way to share a global function or method like listData instead of listBlog or listText and not to copy and paste multiple time on Models.php? function on Laravel's Models file?