定義基本post架構
This commit is contained in:
parent
de7c084c0f
commit
854dd96e22
9
app/Article.php
Normal file
9
app/Article.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Article extends Post
|
||||||
|
{
|
||||||
|
}
|
||||||
9
app/Portfolio.php
Normal file
9
app/Portfolio.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Portfolio extends Post
|
||||||
|
{
|
||||||
|
}
|
||||||
12
app/Post.php
Normal file
12
app/Post.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
abstract class Post extends TranslatableModel
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'title', 'content', 'excerpt', 'user_id', 'feature_image_id'
|
||||||
|
];
|
||||||
|
}
|
||||||
21
app/Traits/PostBlueprintGettable.php
Normal file
21
app/Traits/PostBlueprintGettable.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Traits;
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
|
||||||
|
trait PostBlueprintGettable
|
||||||
|
{
|
||||||
|
public function processSchema(Blueprint $table)
|
||||||
|
{
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->text('title')->comment('標題');
|
||||||
|
$table->text('content')->nullable()->comment('內容');
|
||||||
|
$table->text('excerpt')->nullable()->comment('摘要');
|
||||||
|
$table->unsignedBigInteger('user_id')->comment('作者');
|
||||||
|
$table->unsignedBigInteger('feature_image_id')->nullable()->comment('主圖');
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->foreign('user_id')->references('id')->on('users');
|
||||||
|
$table->foreign('feature_image_id')->references('id')->on('media_files');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -68,6 +68,22 @@ return [
|
|||||||
'editor'
|
'editor'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
// 管理Article
|
||||||
|
'name' => 'admin manage post article',
|
||||||
|
'displayName' => 'adminManagePostArticle',
|
||||||
|
'assignTo' => [
|
||||||
|
'editor'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
// 管理Portfolio
|
||||||
|
'name' => 'admin manage post portfolio',
|
||||||
|
'displayName' => 'adminManagePostPortfolio',
|
||||||
|
'assignTo' => [
|
||||||
|
'editor'
|
||||||
|
]
|
||||||
|
],
|
||||||
],
|
],
|
||||||
// 預設的設定值
|
// 預設的設定值
|
||||||
'options' => [
|
'options' => [
|
||||||
|
|||||||
5
config/posts.php
Normal file
5
config/posts.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
\App\Article::class,
|
||||||
|
\App\Portfolio::class,
|
||||||
|
];
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use App\Traits\PostBlueprintGettable;
|
||||||
|
|
||||||
|
class CreateArticlesTable extends Migration
|
||||||
|
{
|
||||||
|
use PostBlueprintGettable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('articles', function (Blueprint $table) {
|
||||||
|
$this->processSchema($table);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('articles');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use App\Traits\PostBlueprintGettable;
|
||||||
|
|
||||||
|
class CreatePortfoliosTable extends Migration
|
||||||
|
{
|
||||||
|
use PostBlueprintGettable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('portfolios', function (Blueprint $table) {
|
||||||
|
$this->processSchema($table);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('portfolios');
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user