Skip to content

Commit c0b5184

Browse files
committed
wip
1 parent fcdf29e commit c0b5184

6 files changed

Lines changed: 52 additions & 32 deletions

File tree

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.1",
19+
"php": "^8.3",
2020
"illuminate/support": "^9.0 || ^10.0 || ^11.0 || ^12.0",
2121
"javaabu/helpers": "^1.61",
2222
"javaabu/translatable": "^1.1",
@@ -33,7 +33,10 @@
3333
},
3434
"autoload": {
3535
"psr-4": {
36-
"Javaabu\\Cms\\": "src/"
36+
"Javaabu\\Cms\\": "src/",
37+
"Javaabu\\Cms\\Database\\Factories\\": "database/factories/",
38+
"Javaabu\\Cms\\Database\\Seeders\\": "database/seeders/"
39+
3740
}
3841
},
3942
"autoload-dev": {

database/factories/PostFactory.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
11
<?php
22

3-
namespace Database\Factories;
3+
namespace Javaabu\Cms\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
66
use Illuminate\Support\Carbon;
77
use Javaabu\Cms\Models\Post;
88
use Javaabu\Cms\Models\PostType;
99
use Javaabu\Cms\Support\Faker\Factory\ContentBlockFactory;
10+
use Javaabu\Helpers\Enums\PublishStatuses;
1011

1112
class PostFactory extends ContentBlockFactory
1213
{
14+
/**
15+
* The name of the factory's corresponding model.
16+
*
17+
* @var class-string<\Illuminate\Database\Eloquent\Model>
18+
*/
1319
protected $model = Post::class;
1420

1521
public function definition(): array
1622
{
1723
return [
18-
'title' => $this->faker->word(),
19-
'slug' => $this->faker->slug(),
24+
'title' => fake()->words(2, true),
25+
'slug' => fake()->slug(),
2026
'content' => $this->getContentBlock(),
21-
'excerpt' => $this->faker->word(),
22-
'menu_order' => $this->faker->randomNumber(),
23-
'status' => $this->faker->word(),
24-
'published_at' => Carbon::now(),
25-
'created_at' => Carbon::now(),
26-
'updated_at' => Carbon::now(),
27-
'document_no' => $this->faker->word(),
28-
'expire_at' => Carbon::now(),
29-
'format' => $this->faker->word(),
30-
'video_url' => $this->faker->url(),
31-
'page_style' => $this->faker->word(),
32-
'ref_no' => $this->faker->word(),
33-
'recently_updated' => $this->faker->boolean(),
34-
'coords' => $this->faker->word(),
35-
'city_id' => $this->faker->randomNumber(),
36-
27+
'excerpt' => fake()->words(2, true),
28+
'menu_order' => fake()->randomNumber(),
29+
'status' => fake()->randomElement(PublishStatuses::cases()),
30+
// 'published_at' => Carbon::now(),
31+
// 'created_at' => Carbon::now(),
32+
// 'updated_at' => Carbon::now(),
33+
// 'document_no' => fake()->words(2, true),
34+
// 'expire_at' => Carbon::now(),
35+
// 'format' => fake()->words(2, true),
36+
// 'video_url' => fake()->url(),
37+
// 'page_style' => fake()->words(2, true),
38+
// 'ref_no' => fake()->words(2, true),
39+
// 'recently_updated' => fake()->boolean(),
40+
// 'coords' => fake()->words(2, true),
41+
// 'city_id' => fake()->randomNumber(),
42+
//
3743
'type' => random_id_or_generate(PostType::class, 'slug'),
3844
];
3945
}

src/Cms.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ public function registerNormalRoutes(): void
8383
foreach ($post_types as $post_type) {
8484
Route::get($post_type->slug, [config('cms.web.controllers.posts'), 'index'])
8585
->defaults('web_post_type_slug', $post_type->slug)
86-
->name('cms::posts.index.' . $post_type->slug);
86+
->name('web.posts.index.' . $post_type->slug);
8787

8888
Route::get($post_type->slug . '/{post_slug}', [config('cms.web.controllers.posts'), 'show'])
8989
->defaults('web_post_type_slug', $post_type)
90-
->name('cms::posts.show.' . $post_type->slug);
90+
->name('web.posts.show.' . $post_type->slug);
9191

9292
// Route::get($post_type->slug . '/{post_slug}/files', [PostsController::class, 'downloadFiles'])
9393
// ->defaults('web_post_type_slug', $post_type)
94-
// ->name('cms::posts.show.files.' . $post_type->slug);
94+
// ->name('web.posts.show.files.' . $post_type->slug);
9595
}
9696
}
9797

src/Models/Post.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Javaabu\Cms\Models;
44

55
use Carbon\Carbon;
6-
use Database\Factories\PostFactory;
6+
use Javaabu\Cms\Database\Factories\PostFactory;
77
use Illuminate\Database\Eloquent\Builder;
88
use Illuminate\Database\Eloquent\Factories\HasFactory;
99
use Illuminate\Database\Eloquent\Model;
@@ -179,10 +179,10 @@ public function getAdminLinkNameAttribute(): string
179179
* @param string $namespace
180180
* @return string
181181
*/
182-
public function url(string $action = 'show', string $locale = null, string $namespace = 'cms::'): string
182+
public function url(string $action = 'show', string $locale = null, string $namespace = 'web'): string
183183
{
184184
$controller = Str::lower(Str::plural(Str::kebab(class_basename(get_class($this)))));
185-
$controller_action = $namespace . '.' . $controller . '.' . $action;
185+
$controller_action = $namespace . '.' . $controller . '.' . $action . '.' . $this->postType->slug;
186186

187187
$params = [
188188
'post_type' => $this->postType->slug,
@@ -328,9 +328,9 @@ public function translatedPermalink(string $action = 'show', string $locale = nu
328328
$controller = Str::lower(Str::plural(Str::kebab(class_basename(get_class($this)))));
329329

330330
if ($post_type_slug != 'pages') {
331-
$controller_action = 'cms::' . $controller . '.' . $action . '.' . $post_type_slug;
331+
$controller_action = 'web.' . $controller . '.' . $action . '.' . $post_type_slug;
332332
} else {
333-
$controller_action = 'cms::pages.' . $action;
333+
$controller_action = 'web.pages.' . $action;
334334
}
335335

336336
$params = [$locale, $this->slug];
@@ -437,8 +437,13 @@ public function getContentBlocksAttribute(): array
437437
}
438438
}
439439

440-
protected static function newFactory(): PostFactory
440+
protected static function newFactory()
441441
{
442442
return PostFactory::new();
443443
}
444+
445+
// protected static function newFactory(): PostFactory
446+
// {
447+
// return new PostFactory();
448+
// }
444449
}

src/Models/PostType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Javaabu\Cms\Models;
44

55
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
67
use Illuminate\Database\Eloquent\Relations\HasMany;
78
use Javaabu\Cms\Database\Factories\PostTypeFactory;
89
use Javaabu\Helpers\AdminModel\AdminModel;
@@ -104,6 +105,11 @@ public function posts(): HasMany
104105
return $this->hasMany(Post::class, 'type', 'slug');
105106
}
106107

108+
public function categoryType(): BelongsTo
109+
{
110+
return $this->belongsTo(CategoryType::class, 'category_type_id', 'id');
111+
}
112+
107113
protected static function newFactory(): PostTypeFactory
108114
{
109115
return PostTypeFactory::new();

src/Support/Faker/ContentBlockFactory.php renamed to src/Support/Faker/Factory/ContentBlockFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ abstract function definition();
1818

1919
public function getContentBlock()
2020
{
21-
return (new EnglishContentBlock(true))->get();
21+
return (new EnglishContentBlock(fake(), true))->get();
2222
}
2323

2424
public function getLiteContentBlock()
2525
{
26-
return (new EnglishContentBlock(true, true))->get();
26+
return (new EnglishContentBlock(fake(), true, true))->get();
2727
}
2828
}

0 commit comments

Comments
 (0)