Add hashtag model/migration and pivot table

pull/9/head
Daniel Supernault 2018-05-19 20:57:55 -06:00
rodzic 92c0ef8a74
commit d8303e7de5
3 zmienionych plików z 97 dodań i 0 usunięć

28
app/Hashtag.php 100644
Wyświetl plik

@ -0,0 +1,28 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Hashtag extends Model
{
protected $fillable = ['name','slug'];
public function posts()
{
return $this->hasManyThrough(
Status::class,
StatusHashtag::class,
'hashtag_id',
'id',
'id',
'status_id'
);
}
public function url()
{
return config('routes.hashtag.base') . $this->slug;
}
}

Wyświetl plik

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateHashtagsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('hashtags', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->unique()->index();
$table->string('slug')->unique()->index();
$table->boolean('is_nsfw')->default(false);
$table->boolean('is_banned')->default(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('hashtags');
}
}

Wyświetl plik

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateStatusHashtagsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('status_hashtags', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('status_id')->unsigned()->index();
$table->bigInteger('hashtag_id')->unsigned()->index();
$table->unique(['status_id', 'hashtag_id']);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('status_hashtags');
}
}