1
我已按照eloquent-sluggable中的安裝指南進行操作。遵循所有安裝指南並重新安裝cviebrock/eloquent-sluggable不起作用
這是我郵政模型結構:
namespace App;
use Cviebrock\EloquentSluggable\SluggableInterface;
use Cviebrock\EloquentSluggable\SluggableTrait;
use Illuminate\Database\Eloquent\Model;
class Post extends Model implements SluggableInterface
{
use SluggableTrait;
protected $sluggable = [
'build_from' => 'post_title',
'save_to' => 'post_alias',
'unique' => true
];
protected $guarded = ['hits', 'comments_count', 'created_at', 'updated_at'];
protected $primaryKey = 'post_id';
protected $dateFormat = 'U';
public function post_pics()
{
return $this->hasMany('App\PostPics');
}
public function categories()
{
return $this->belongsToMany('App\Category', 'category_post', 'post_id', 'cat_id');
}
public function getCreatedAtAttribute($value){
return $value;
}
}
而且在app.php添加相應的項,服務提供商文件:
yajra\Datatables\DatatablesServiceProvider::class,
Spatie\Glide\GlideServiceProvider::class,
Illuminate\Html\HtmlServiceProvider::class,
Cviebrock\EloquentSluggable\SluggableServiceProvider::class,
但是,當插入新行發佈表,post_alias字段爲空:
$newPost = new Post(['post_title'=>'How are you']);
$newPost->save();
什麼是問題,我該如何解決這個問題?
更新:
我使用Laravel Framework版本5.1.23(LTS)。然而,當我在另一個項目的基礎上使用這個包但是版本5.1.19,它工作正常。