Skip to content

Commit 454a7ff

Browse files
committed
wip
1 parent 8cc8b35 commit 454a7ff

File tree

20 files changed

+1983
-9
lines changed

20 files changed

+1983
-9
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
],
1818
"require": {
1919
"php": "^8.1",
20-
"illuminate/support": "^9.0 || ^10.0 || ^11.0 || ^12.0"
20+
"illuminate/support": "^9.0 || ^10.0 || ^11.0 || ^12.0",
21+
"javaabu/helpers": "^1.61",
22+
"javaabu/translatable": "^1.1"
2123
},
2224
"require-dev": {
2325
"laravel/pint": "^1.14",

config/cms.php renamed to config/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
|
1111
*/
1212

13-
// TODO
13+
'should_translate' => false,
1414
];
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
return new class extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::create('category_types', function (Blueprint $table) {
16+
$table->id();
17+
$table->string('name');
18+
$table->string('singular_name');
19+
$table->string('slug')->unique();
20+
$table->timestamps();
21+
$table->jsonTranslatable();
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*
28+
* @return void
29+
*/
30+
public function down()
31+
{
32+
Schema::dropIfExists('category_types');
33+
}
34+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
use Javaabu\Translatable\JsonTranslatable\JsonTranslatableSchema;
7+
8+
return new class extends Migration
9+
{
10+
public function up()
11+
{
12+
Schema::create('post_types', function (Blueprint $table) {
13+
$table->id();
14+
$table->string('name');
15+
$table->string('singular_name');
16+
$table->string('slug')->unique();
17+
$table->string('icon');
18+
$table->foreignId('category_type_id')
19+
->nullable()
20+
->constrained()
21+
->nullOnDelete();
22+
$table->json('features')->nullable();
23+
$table->string('og_description')->nullable();
24+
$table->unsignedInteger('order_column')->default(0);
25+
$table->timestamps();
26+
$table->jsonTranslatable();
27+
});
28+
}
29+
30+
public function down()
31+
{
32+
Schema::dropIfExists('post_types');
33+
}
34+
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\DB;
4+
use Illuminate\Support\Facades\Schema;
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Database\Migrations\Migration;
7+
8+
return new class extends Migration
9+
{
10+
public function up()
11+
{
12+
Schema::create('posts', function (Blueprint $table) {
13+
$table->id();
14+
$table->string('type');
15+
16+
$table->text('title');
17+
$table->string('slug');
18+
$table->text('content')->nullable();
19+
$table->text('excerpt')->nullable();
20+
$table->unsignedInteger('menu_order')->index()->default(0);
21+
$table->string('status')->index();
22+
$table->dateTime('published_at')->index();
23+
$table->timestamps();
24+
$table->softDeletes();
25+
26+
// Feature values - Always nullable
27+
$table->string('document_no')->index()->nullable();
28+
$table->dateTime('expire_at')->index()->nullable();
29+
$table->string('format')->index()->nullable();
30+
$table->text('video_url')->nullable();
31+
$table->string('page_style')->nullable();
32+
$table->string('ref_no')->index()->nullable();
33+
// $table->foreignId('sidebar_menu_id')->nullable()->constrained('menus')->nullOnDelete();
34+
$table->boolean('recently_updated')->index()->default(false);
35+
// Coordinates
36+
$table->text('coords')->nullable();
37+
$table->foreignId('city_id')->nullable()->index();
38+
39+
$table->jsonTranslatable();
40+
41+
// slugs must be unique for the category
42+
$table->unique(['slug', 'type'], 'unique_type_slug');
43+
44+
$table->foreign('type')
45+
->references('slug')
46+
->on('post_types')
47+
->onDelete('cascade')
48+
->onUpdate('cascade');
49+
});
50+
51+
// Full Text Index
52+
if (! app()->runningUnitTests()) {
53+
DB::statement("ALTER TABLE posts ADD FULLTEXT fulltext_index (`title`, `content`)");
54+
}
55+
}
56+
57+
public function down()
58+
{
59+
Schema::dropIfExists('posts');
60+
}
61+
};

ide.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "https://laravel-ide.com/schema/laravel-ide-v2.json",
3+
"completions": [
4+
{
5+
"complete": "routeName",
6+
"condition": [
7+
{
8+
"functionNames": ["translate_route"],
9+
"parameters": [1]
10+
}
11+
]
12+
},
13+
{
14+
"complete": "configKey",
15+
"options": {
16+
"prefix": "defaults"
17+
},
18+
"condition": [
19+
{
20+
"functionNames": ["get_setting"],
21+
"parameters": [1]
22+
}
23+
]
24+
}
25+
]
26+
}

src/Cms.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Javaabu\Cms;
4+
5+
use Illuminate\Support\Facades\Route;
6+
use Illuminate\Support\Str;
7+
use Javaabu\Cms\Http\Controllers\PostsController;
8+
use Javaabu\Cms\Models\PostType;
9+
use Javaabu\Translatable\Facades\Languages;
10+
11+
class Cms {
12+
public function registerPostTypes($postTypes): void
13+
{
14+
foreach ($postTypes as $slug => $data) {
15+
$type = PostType::whereSlug($slug)->first();
16+
17+
if (! $type) {
18+
$type = new PostType();
19+
}
20+
21+
$name = Str::title(str_replace('-', ' ', $slug));
22+
$type->name = $data['name'] ?? $name;
23+
$type->singular_name = $data['name_singular'] ?? Str::singular($name);
24+
$type->lang = Languages::default();
25+
26+
$type->slug = $slug;
27+
$type->icon = $data['icon'];
28+
29+
30+
$category_type = CategoryType::whereSlug(Str::singular($slug) . '-categories')->first();
31+
$type->categoryType()->associate($category_type);
32+
33+
$type->features = $data['features'];
34+
35+
$type->order_column = $count;
36+
37+
$type->save();
38+
}
39+
}
40+
41+
public function registerRoutes(): void
42+
{
43+
Route::group([
44+
'prefix' => '{post_type}',
45+
'as' => 'cms::',
46+
], function () {
47+
Route::match(['PUT', 'PATCH'], '/', [PostsController::class, 'bulk'])->name('bulk');
48+
Route::get('/trash', [PostsController::class, 'trash'])->name('trash');
49+
Route::post('/{id}/restore', [PostsController::class, 'restore'])->name('restore');
50+
Route::delete('/{id}/force-delete', [PostsController::class, 'forceDelete'])->name('force-delete');
51+
Route::get('/', [PostsController::class, 'index'])->name('index');
52+
Route::get('/create', [PostsController::class, 'create'])->name('create');
53+
Route::post('/', [PostsController::class, 'store'])->name('store');
54+
Route::get('/{post}', [PostsController::class, 'show'])->name('show');
55+
Route::get('/{post}/edit', [PostsController::class, 'edit'])->name('edit');
56+
Route::match(['PUT', 'PATCH'], '/{post}', [PostsController::class, 'update'])->name('update');
57+
Route::delete('/{post}', [PostsController::class, 'destroy'])->name('destroy');
58+
});
59+
}
60+
61+
/**
62+
* @return void
63+
*/
64+
public function registerTranslatableRoutes(): void
65+
{
66+
Route::group([
67+
'prefix' => '{language}',
68+
], function () {
69+
$this->registerRoutes();
70+
});
71+
}
72+
}

0 commit comments

Comments
 (0)