浏览代码

Add mention model/migration/translation

Daniel Supernault 7 年之前
父节点
当前提交
33ff1f7829
共有 3 个文件被更改,包括 68 次插入0 次删除
  1. 33 0
      app/Mention.php
  2. 34 0
      database/migrations/2018_06_08_003624_create_mentions_table.php
  3. 1 0
      resources/lang/en/notification.php

+ 33 - 0
app/Mention.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Mention extends Model
+{
+
+    public function profile()
+    {
+      return $this->belongsTo(Profile::class, 'profile_id', 'id');
+    }
+
+    public function status()
+    {
+      return $this->belongsTo(Status::class);
+    }
+
+    public function toText()
+    {
+      $actorName = $this->status->profile->username;
+      return "{$actorName} " . __('notification.mentionedYou');
+    }
+
+    public function toHtml()
+    {
+      $actorName = $this->status->profile->username;
+      $actorUrl = $this->status->profile->url();
+      return "<a href='{$actorUrl}' class='profile-link'>{$actorName}</a> " .
+          __('notification.mentionedYou');
+    }
+}

+ 34 - 0
database/migrations/2018_06_08_003624_create_mentions_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateMentionsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('mentions', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->bigInteger('status_id')->unsigned();
+            $table->bigInteger('profile_id')->unsigned();
+            $table->boolean('local')->default(true);
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('mentions');
+    }
+}

+ 1 - 0
resources/lang/en/notification.php

@@ -5,5 +5,6 @@ return [
   'likedPhoto' => 'liked your photo.',
   'startedFollowingYou' => 'started following you.',
   'commented' => 'commented on your post.',
+  'mentionedYou' => 'mentioned you.'
 
 ];