diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index a6d1341..41db4ef 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -887,6 +887,13 @@ function success($data = null, $message = null, $meta = [], $og = [], $twitter = ]); } +/** + * @param $errors + * @param $status + * @param $message + * @param $data + * @return \Illuminate\Http\JsonResponse + */ function errors($errors, $status = 422, $message = null, $data = null) { return response()->json([ @@ -896,3 +903,8 @@ function errors($errors, $status = 422, $message = null, $data = null) "data" => $data, ], $status); } + +function readable($text) +{ + return ucfirst(trim(str_replace(['-','_'],' ',$text))); +} diff --git a/app/Http/Controllers/Admin/PostController.php b/app/Http/Controllers/Admin/PostController.php index 0dd3f86..735f459 100644 --- a/app/Http/Controllers/Admin/PostController.php +++ b/app/Http/Controllers/Admin/PostController.php @@ -57,7 +57,7 @@ class PostController extends XController $post->status = $request->input('status'); $post->group_id = $request->input('group_id'); $post->user_id = auth()->id(); - $post->is_pinned = $request->has('is_pinned'); + $post->is_pinned = $request->has('is_pin'); $post->icon = $request->input('icon'); if ($post->hash == null) { diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 75daeeb..e2f3ff4 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -11,59 +11,75 @@ use Spatie\Tags\Tag; class ClientController extends Controller { + + public $paginate = 10; + // - public function welcome(){ + public function welcome() + { $area = 'index'; $title = config('app.name'); $subtitle = getSetting('subtitle'); - return view('client.welcome',compact('area','title','subtitle')); + return view('client.welcome', compact('area', 'title', 'subtitle')); } - public function post(Post $post){ + public function post(Post $post) + { $area = 'post'; $title = $post->title; $subtitle = $post->subtitle; $post->increment('view'); - return view('client.post',compact('area','post','title','subtitle')); + return view('client.post', compact('area', 'post', 'title', 'subtitle')); + } + + public function posts() + { + $area = 'posts-list'; + $title = __("Posts list"); + $subtitle = ''; + $posts = Post::where('status', 1)->orderByDesc('id')->paginate($this->paginate); + return view('client.posts', compact('area', 'posts', 'title', 'subtitle')); } - public function tag($slug){ + public function tag($slug) + { - $tag = Tag::where('slug->'.config('app.locale'),'like',$slug)->first(); + $tag = Tag::where('slug->' . config('app.locale'), 'like', $slug)->first(); return $tag; } - public function submitComment(Request $request){ + public function submitComment(Request $request) + { $request->validate([ - 'commentable_type' => ['required','string','min:5'], - 'commentable_id' => ['required','integer'], - 'message' => ['required','string','min:5'], - 'parent_id' => ['nullable','integer'], + 'commentable_type' => ['required', 'string', 'min:5'], + 'commentable_id' => ['required', 'integer'], + 'message' => ['required', 'string', 'min:5'], + 'parent_id' => ['nullable', 'integer'], ]); $comment = new Comment(); - if (!auth()->check() && !auth('customer')->check()){ + if (!auth()->check() && !auth('customer')->check()) { $request->validate([ - 'name' => ['required','string','min:2'], - 'email' => ['required','email'], + 'name' => ['required', 'string', 'min:2'], + 'email' => ['required', 'email'], ]); $comment->name = $request->name; $comment->email = $request->email; $comment->status = 0; - }else{ - if (auth()->check() ){ - $comment->commentator_type = User::class; - $comment->commentator_id = auth()->id(); + } else { + if (auth()->check()) { + $comment->commentator_type = User::class; + $comment->commentator_id = auth()->id(); $comment->status = 1; - }else{ - $comment->commentator_type = Customer::class; - $comment->commentator_id = auth('customer')->id(); + } else { + $comment->commentator_type = Customer::class; + $comment->commentator_id = auth('customer')->id(); $comment->status = 0; } } - $comment->parent_id = $request->input('parent_id',null); + $comment->parent_id = $request->input('parent_id', null); $comment->body = $request->input('message'); $comment->commentable_type = $request->input('commentable_type'); $comment->commentable_id = $request->input('commentable_id'); @@ -73,7 +89,8 @@ class ClientController extends Controller return redirect()->back()->with(['message' => __('Your comment has been submitted')]); } - public function search(Request $request){ + public function search(Request $request) + { } } diff --git a/app/Http/Requests/PostSaveRequest.php b/app/Http/Requests/PostSaveRequest.php index ba1b23e..c9cc74f 100644 --- a/app/Http/Requests/PostSaveRequest.php +++ b/app/Http/Requests/PostSaveRequest.php @@ -25,8 +25,8 @@ class PostSaveRequest extends FormRequest 'title' => ['required', 'string', 'max:255', 'min:2'], 'subtitle' => ['nullable', 'string', 'max:2048'], 'body' => ['required', 'string', 'min:5'], - 'status' => ['required', 'boolean'], - 'is_pin' => ['nullable', 'boolean'], + 'status' => ['required'], + 'is_pin' => ['nullable'], 'image' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048'], 'icon' => ['nullable', 'string', 'min:3'], 'group_id' => ['required', 'exists:groups,id'], diff --git a/app/Models/Post.php b/app/Models/Post.php index a602166..2598718 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -102,7 +102,7 @@ class Post extends Model implements HasMedia } public function mainGroup(){ - return $this->belongsTo(Group::class); + return $this->belongsTo(Group::class,'group_id'); } public function attachs(){ diff --git a/resources/views/admin/areas/area-list.blade.php b/resources/views/admin/areas/area-list.blade.php index d14b961..30f8fe5 100644 --- a/resources/views/admin/areas/area-list.blade.php +++ b/resources/views/admin/areas/area-list.blade.php @@ -1,3 +1,4 @@ + @extends('layouts.app') @section('title') @@ -9,7 +10,7 @@
- {{__(ucfirst($area->name))}} + {{__(readable($area->name))}}
@endforeach diff --git a/resources/views/admin/posts/post-form.blade.php b/resources/views/admin/posts/post-form.blade.php index d1471e4..224cf9d 100644 --- a/resources/views/admin/posts/post-form.blade.php +++ b/resources/views/admin/posts/post-form.blade.php @@ -175,9 +175,8 @@
-
- is_pin??0) != 0) + is_pinned??0) != 0) checked @endif type="checkbox" id="ispin"> diff --git a/resources/views/client/posts.blade.php b/resources/views/client/posts.blade.php new file mode 100644 index 0000000..e31f1c2 --- /dev/null +++ b/resources/views/client/posts.blade.php @@ -0,0 +1,13 @@ +@extends('website.inc.website-layout') + +@section('title') + {{$title}} - {{config('app.name')}} +@endsection +@section('content') +
+ @foreach(getParts($area) as $part) + @php($p = $part->getBladeWithData()) + @include($p['blade'],['data' => $p['data']]) + @endforeach +
+@endsection diff --git a/resources/views/segments/posts_page/SimplePostList/SimplePostList.blade.php b/resources/views/segments/posts_page/SimplePostList/SimplePostList.blade.php new file mode 100644 index 0000000..7e3160d --- /dev/null +++ b/resources/views/segments/posts_page/SimplePostList/SimplePostList.blade.php @@ -0,0 +1,47 @@ +
+
+
+ @foreach(\App\Models\Post::where('status',1)->where('is_pinned',1)->limit(2)->get() as $post) +
+
+
+ {{$post->mainGroup->name}} +
+ + {{$post->title}} + +
+

+ {{$post->title}} +

+ + {{$post->created_at->ldate('Y/m/d l')}} + +
+
+
+ @endforeach +
+
+ @foreach($posts as $post) +
+ {{$post->title}} +

+ {{$post->title}} +

+
+ {{$post->created_at->ldate('Y/m/d l')}} +
+

+ {{$post->subtitle}} +
+ + {{__("Read more")}} + +

+
+ @endforeach + {{$posts->links()}} +
+
diff --git a/resources/views/segments/posts_page/SimplePostList/SimplePostList.js b/resources/views/segments/posts_page/SimplePostList/SimplePostList.js new file mode 100644 index 0000000..e69de29 diff --git a/resources/views/segments/posts_page/SimplePostList/SimplePostList.json b/resources/views/segments/posts_page/SimplePostList/SimplePostList.json new file mode 100644 index 0000000..dd52437 --- /dev/null +++ b/resources/views/segments/posts_page/SimplePostList/SimplePostList.json @@ -0,0 +1,10 @@ +{ + "name": "SimplePostList", + "version": "1.0", + "author": "xStack", + "email": "xshop@xstack.ir", + "license": "GPL-3.0-or-later", + "url": "https:\/\/xstack.ir", + "author_url": "https:\/\/4xmen.ir", + "packages": [] +} \ No newline at end of file diff --git a/resources/views/segments/posts_page/SimplePostList/SimplePostList.php b/resources/views/segments/posts_page/SimplePostList/SimplePostList.php new file mode 100644 index 0000000..f673eb7 --- /dev/null +++ b/resources/views/segments/posts_page/SimplePostList/SimplePostList.php @@ -0,0 +1,21 @@ +group(function (){ // index Route::get('/', [\App\Http\Controllers\ClientController::class,'welcome'])->name('welcome'); - Route::get('/{post}', [\App\Http\Controllers\ClientController::class,'post'])->name('post'); + Route::get('/posts', [\App\Http\Controllers\ClientController::class,'posts'])->name('posts'); Route::get('/tag/{post}', [\App\Http\Controllers\ClientController::class,'tag'])->name('tag'); Route::get('/search', [\App\Http\Controllers\ClientController::class,'search'])->name('search'); + Route::get('/{post}', [\App\Http\Controllers\ClientController::class,'post'])->name('post'); Route::post('/comment/submit', [\App\Http\Controllers\ClientController::class,'submitComment'])->name('comment.submit');