
PK 
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Category extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'categories';
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'parent_id','lft','rght','category_sortby','category_name','category_desc','category_slug','category_image','category_imagethumb','isvisible','isactive','isdelete','addedby','created_at','updated_at','deleted_at','visitor'
];
/**
* Scope a query to only include popular users.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopular($query)
{
return $query->where('votes', '>', 100);
}
/**
* Scope a query to only include active users.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeActive($query)
{
return $query->where('isactive', 1);
}
/**
* Get the index name for the model.
*
* @return string
*/
public function parent()
{
return $this->belongsTo('App\Category', 'parent_id');
}
public function children()
{
return $this->hasMany('App\Category', 'parent_id');
}
/* public function childs() {
return $this->hasMany('App\Category','parent_id','id') ;
} */
/**
* Get excerpt from string
*
* @param String $str String to get an excerpt from
* @param Integer $startPos Position int string to start excerpt from
* @param Integer $maxLength Maximum length the excerpt may be
* @return String excerpt
*/
public static function getExcerpt($str, $startPos = 0, $maxLength = 50) {
if(strlen($str) > $maxLength) {
$excerpt = substr($str, $startPos, $maxLength - 6);
$lastSpace = strrpos($excerpt, ' ');
$excerpt = substr($excerpt, 0, $lastSpace);
$excerpt .= ' [...]';
} else {
$excerpt = $str;
}
return $excerpt;
}
}


PK 99