diff --git a/app/Http/Controllers/Front/HomeController.php b/app/Http/Controllers/Front/HomeController.php index 2e353db..ff98b65 100644 --- a/app/Http/Controllers/Front/HomeController.php +++ b/app/Http/Controllers/Front/HomeController.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Controller; use App\Models\Category; use App\Models\CountryLocale; +use App\Models\Post; use Illuminate\Http\Request; use Stevebauman\Location\Facades\Location; @@ -27,7 +28,35 @@ public function country(Request $request, $country) $request->session()->put('view_country_locale', $country_locale); - return view('front.country', ['country_locale' => $country_locale]); + $featured_posts = Post::select('posts.*') + ->join('post_categories','posts.id','=', 'post_categories.post_id') + ->join('categories','post_categories.category_id','=', 'categories.id') + ->whereNotNull('post_categories.id') + ->whereNotNull('categories.id') + ->where('categories.country_locale_slug', $country_locale->slug) + ->where('posts.featured', true) + ->where('posts.status', 'publish') + ->orderBy('posts.updated_at', 'desc') + ->take(3) + ->get(); + + + $latest_posts = Post::select('posts.*') + ->join('post_categories','posts.id','=', 'post_categories.post_id') + ->join('categories','post_categories.category_id','=', 'categories.id') + ->whereNotNull('post_categories.id') + ->whereNotNull('categories.id') + ->where('categories.country_locale_slug', $country_locale->slug) + ->where('posts.featured', true) + ->whereNotIn('posts.id', $featured_posts->pluck('id')->toArray()) + ->where('posts.status', 'publish') + ->orderBy('posts.updated_at', 'desc') + ->distinct() + ->take(20) + ->get(); + + return view('front.country', compact('country_locale','featured_posts','latest_posts') + ); } return redirect()->route('home.country', ['country' => config('platform.general.fallback_country_slug')]); @@ -50,6 +79,13 @@ public function countryCategory(Request $request, $country, $category) return view('front.country_category', ['country_locale' => $country_locale, 'category' => $category]); } + public function all(Request $request, $country) + { + $country_locale = CountryLocale::where('slug', $country)->first(); + + return view('front.country_all', ['country_locale' => $country_locale]); + } + public function posts(Request $request, $country) { return "{$country} : all posts"; diff --git a/app/Models/Author.php b/app/Models/Author.php new file mode 100644 index 0000000..9ecaef2 --- /dev/null +++ b/app/Models/Author.php @@ -0,0 +1,50 @@ + 'bool', + 'public' => 'bool' + ]; + + protected $fillable = [ + 'name', + 'avatar', + 'bio', + 'enabled', + 'public' + ]; + + public function posts() + { + return $this->hasMany(Post::class); + } +} diff --git a/app/Models/DraftPost.php b/app/Models/DraftPost.php new file mode 100644 index 0000000..8a503af --- /dev/null +++ b/app/Models/DraftPost.php @@ -0,0 +1,11 @@ + 'int', + 'body' => 'json', + 'comment_count' => 'int', + 'likes_count' => 'int' + ]; + + protected $fillable = [ + 'title', + 'slug', + 'excerpt', + 'author_id', + 'featured_image', + 'editor', + 'body', + 'post_format', + 'comment_count', + 'likes_count', + 'status' + ]; + + public function author() + { + return $this->belongsTo(Author::class); + } + + public function post_categories() + { + return $this->hasMany(PostCategory::class); + } +} diff --git a/app/Models/PostCategory.php b/app/Models/PostCategory.php new file mode 100644 index 0000000..48382d8 --- /dev/null +++ b/app/Models/PostCategory.php @@ -0,0 +1,49 @@ + 'int', + 'category_id' => 'int' + ]; + + protected $fillable = [ + 'post_id', + 'category_id' + ]; + + public function category() + { + return $this->belongsTo(Category::class); + } + + public function post() + { + return $this->belongsTo(Post::class); + } +} diff --git a/database/migrations/2023_07_26_155110_create_authors_table.php b/database/migrations/2023_07_26_155110_create_authors_table.php new file mode 100644 index 0000000..1ce1169 --- /dev/null +++ b/database/migrations/2023_07_26_155110_create_authors_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name'); + $table->string('avatar'); + $table->string('bio'); + $table->boolean('enabled')->default(true); + $table->boolean('public')->default(true); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('authors'); + } +}; diff --git a/database/migrations/2023_07_26_155118_create_posts_table.php b/database/migrations/2023_07_26_155118_create_posts_table.php new file mode 100644 index 0000000..bf153cb --- /dev/null +++ b/database/migrations/2023_07_26_155118_create_posts_table.php @@ -0,0 +1,41 @@ +id(); + $table->string('title')->nullable(); + $table->string('slug')->nullable(); + $table->mediumText('excerpt')->nullable(); + $table->foreignId('author_id')->nullable(); + $table->boolean('featured')->default(false); + $table->string('featured_image'); + $table->enum('editor', ['editorjs'])->default('editorjs'); + $table->json('body')->nullable(); + $table->enum('post_format',['standard'])->default('standard'); + $table->integer('comment_count')->default(0); + $table->integer('likes_count')->default(0); + $table->enum('status', ['publish','future','draft','private','trash'])->default('draft'); + $table->timestamps(); + + $table->foreign('author_id')->references('id')->on('authors'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('posts'); + } +}; diff --git a/database/migrations/2023_07_26_161726_create_post_categories_table.php b/database/migrations/2023_07_26_161726_create_post_categories_table.php new file mode 100644 index 0000000..8b99dcc --- /dev/null +++ b/database/migrations/2023_07_26_161726_create_post_categories_table.php @@ -0,0 +1,32 @@ +id(); + $table->foreignId('post_id'); + $table->foreignId('category_id'); + + $table->foreign('post_id')->references('id')->on('posts'); + $table->foreign('category_id')->references('id')->on('categories'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('post_categories'); + } +}; diff --git a/database/seeders/PostsSeeder.php b/database/seeders/PostsSeeder.php new file mode 100644 index 0000000..c8103dc --- /dev/null +++ b/database/seeders/PostsSeeder.php @@ -0,0 +1,70 @@ +get(); + + $categories = Category::Where('enabled', true)->get(); + + + $faker = FakerFactory::create(); + + + for ($i = 0; $i < 20; $i++) { + + $photo_id = (($i + 1) % 16); // placekitten has only 16 photos + + $post_title = $faker->sentence; + $post_slug = Str::slug($post_title, "-"); + + $cloned_authors = clone $authors; + $cloned_categories = clone $categories; + + $createdAt = $faker->dateTimeBetween('-1 year', 'now'); + + + $post = Post::create([ + "title" => $post_title, + "slug" => $post_slug, + "excerpt" => $faker->paragraph, + "author_id" => $cloned_authors->random()->first()->id, + "featured" => rand(0,1), + "featured_image" => "https://placekitten.com/1920/1080?image={$photo_id}", + "editor" => "editorjs", + "post_format" => "standard", + "comment_count" => rand(0,100), + "likes_count" => rand(0,100), + "status" => "publish", + "body" => "{\"time\":1563816717958,\"blocks\":[{\"data\":{\"text\":\"Editor.js\",\"level\":2},\"type\":\"header\"},{\"data\":{\"text\":\"Hey. Meet the new Editor. On this page you can see it in action \\u2014 try to edit this text.\"},\"type\":\"paragraph\"},{\"data\":{\"text\":\"Key features\",\"level\":3},\"type\":\"header\"},{\"data\":{\"items\":[\"It is a block-styled editor\",\"It returns clean data output in JSON\",\"Designed to be extendable and pluggable with a simple API\"],\"style\":\"unordered\"},\"type\":\"list\"},{\"data\":{\"text\":\"What does it mean \\u00abblock-styled editor\\u00bb\",\"level\":3},\"type\":\"header\"},{\"data\":{\"text\":\"Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc<\\\/mark>. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor's Core.\"},\"type\":\"paragraph\"},{\"data\":{\"text\":\"There are dozens of ready-to-use Blocks<\\\/a> and the simple API<\\\/a> for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games.\"},\"type\":\"paragraph\"},{\"data\":{\"text\":\"What does it mean clean data output\",\"level\":3},\"type\":\"header\"},{\"data\":{\"text\":\"Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below\"},\"type\":\"paragraph\"},{\"data\":{\"text\":\"Given data can be used as you want: render with HTML for Web clients<\\\/code>, render natively for mobile apps<\\\/code>, create markup for Facebook Instant Articles<\\\/code> or Google AMP<\\\/code>, generate an audio version<\\\/code> and so on.\"},\"type\":\"paragraph\"},{\"data\":{\"text\":\"Clean data is useful to sanitize, validate and process on the backend.\"},\"type\":\"paragraph\"},{\"data\":[],\"type\":\"delimiter\"},{\"data\":{\"text\":\"We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make it's core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. \\ud83d\\ude0f\"},\"type\":\"paragraph\"},{\"data\":{\"file\":{\"url\":\"https:\\\/\\\/codex.so\\\/upload\\\/redactor_images\\\/o_e48549d1855c7fc1807308dd14990126.jpg\"},\"caption\":\"Image caption\",\"stretched\":false,\"withBorder\":true,\"withBackground\":false},\"type\":\"image\"}],\"version\":\"2.15.0\"}", + 'created_at' => $createdAt, + 'updated_at' => $createdAt, + ]); + + $post_category = PostCategory::create([ + 'post_id' => $post->id, + 'category_id' => $cloned_categories->random()->first()->id, + ]); + } + } +} diff --git a/resources/views/front/country.blade.php b/resources/views/front/country.blade.php index 199aaff..e36a0b1 100644 --- a/resources/views/front/country.blade.php +++ b/resources/views/front/country.blade.php @@ -13,23 +13,25 @@

Featured Articles

@@ -37,25 +39,24 @@
-
+

What's New in {{ get_country_name_by_iso($country_locale->country_iso) }}

- @for ($i = 1; $i <= 12; $i++) -
+ @foreach ($latest_posts as $post) +
-
+
diff --git a/resources/views/front/country_all.blade.php b/resources/views/front/country_all.blade.php new file mode 100644 index 0000000..3b074da --- /dev/null +++ b/resources/views/front/country_all.blade.php @@ -0,0 +1,70 @@ +@extends('layouts.front.app') + +@section('content') +
+ + + +
+
+ + +
+
+ +
+

All {{ $country_locale->name }} News

+

+ The latest {{ $country_locale->name }} news, brought to you by {{ config('app.name') }} +

+
+ + @for($i = 0; $i < 10; $i++) +
+ + + + +
+ +
+
+ Here is why a kitten catches mice faster than an adult cat.
+

+ This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer. +

+ +

+ #technology #gadgets + 3 min read +

+ +
+ + ... + + +
+ + +
+ @endfor + + +
+ +
+
+ +
+ +
+@endsection \ No newline at end of file diff --git a/resources/views/front/country_category.blade.php b/resources/views/front/country_category.blade.php index d8ed1cd..0a7fd17 100644 --- a/resources/views/front/country_category.blade.php +++ b/resources/views/front/country_category.blade.php @@ -3,18 +3,21 @@ @section('content')
-
+ +
+
+ + +
+
+ +

{{ $category->name }}

{{ $category->description }}

-
-
-
-
- @for($i = 0; $i < 10; $i++)
@@ -30,12 +33,12 @@

#technology #gadgets - Updated 3 mins ago + 3 min read

- ... + ...
@@ -43,10 +46,22 @@
@endfor + +
+ +
-
+{{--
b -
+
--}}
diff --git a/resources/views/front/post.blade.php b/resources/views/front/post.blade.php new file mode 100644 index 0000000..3b9f789 --- /dev/null +++ b/resources/views/front/post.blade.php @@ -0,0 +1,7 @@ +@extends('layouts.front.app') + +@section('content') +
+ Post +
+@endsection \ No newline at end of file diff --git a/resources/views/layouts/front/navigation.blade.php b/resources/views/layouts/front/navigation.blade.php index a003024..48b590b 100644 --- a/resources/views/layouts/front/navigation.blade.php +++ b/resources/views/layouts/front/navigation.blade.php @@ -41,6 +41,9 @@