You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
625 B

  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Tag extends Model
  5. {
  6. protected $fillable = ['name'];
  7. public static function firstOrCreateSafe(array $attributes, array $values = [])
  8. {
  9. try {
  10. return static::firstOrCreate($attributes, $values);
  11. } catch (\PDOException $e) {
  12. /*
  13. * When an article is received the related tags can be saved
  14. * simultaneously by different processes in the DB
  15. */
  16. }
  17. }
  18. public function posts()
  19. {
  20. return $this->belongsToMany('App\Post')->withTimestamps();
  21. }
  22. }