Modelo Articulo
<?php
namespace Blog;
use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
use Carbon\Carbon;
class Articulo extends Model{
use Sluggable;
/**
* Return the sluggable configuration array for this model.
*
* @return array
*/
public function sluggable(){
return [
'slug' => [
'source' => 'titulo'
]
];
}
protected $table = 'articulos';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['titulo', 'contenido','slug','path','etiqueta','user_id','categoria_id'];
public function setPathAttribute($path){
if(! empty($path)){
$name = Carbon::now()->second.$path->getClientOriginalName();
$this->attributes['path'] = $name;
\Storage::disk('local')->put($name, \File::get($path));
}
}
public function categoria(){
return $this->belongsTo('Blog\Categoria');
}
public function user(){
return $this->belongsTo('Blog\User');
}
public function scopeTitulo($query, $titulo){//Funcion para hacer una busqueda
if(trim($titulo) != ''){ //Funcion trim para eliminar los espacios
$query->where(\DB::raw("titulo"),"LIKE","%$titulo%");
}
}
}