diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 11127a6..eb41d96 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -2,7 +2,10 @@ namespace App\Http\Controllers; +use App\Models\Comment; +use App\Models\Customer; use App\Models\Post; +use App\Models\User; use Illuminate\Http\Request; use Spatie\Tags\Tag; @@ -29,4 +32,44 @@ class ClientController extends Controller $tag = Tag::where('slug->'.config('app.locale'),'like',$slug)->first(); return $tag; } + + + 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'], + ]); + + $comment = new Comment(); + if (!auth()->check() && !auth('customer')->check()){ + $request->validate([ + '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(); + $comment->status = 1; + }else{ + $comment->commentator_type = Customer::class; + $comment->commentator_id = auth('customer')->id(); + $comment->status = 0; + } + } + + $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'); + $comment->ip = request()->ip(); + $comment->save(); + + return redirect()->back()->with(['message' => __('Your comment has been submitted')]); + } } diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 1714242..bada68d 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -16,7 +16,7 @@ class Comment extends Model public function children() { - return $this->hasMany(Comment::class, 'sub_comment_id'); + return $this->hasMany(Comment::class, 'parent_id'); } public function parent() diff --git a/app/Models/Part.php b/app/Models/Part.php index 9419a48..4e46bc5 100644 --- a/app/Models/Part.php +++ b/app/Models/Part.php @@ -10,19 +10,23 @@ class Part extends Model use HasFactory; - public function getBlade(){ - $className= ucfirst($this->part); + public function getBlade() + { + $className = ucfirst($this->part); $handle = "\\Resources\\Views\\Segments\\$className"; $handle::onMount($this); - return 'segments.'.$this->segment.'.'.$this->part.'.'.$this->part; + return 'segments.' . $this->segment . '.' . $this->part . '.' . $this->part; } - public function getBladeWithData(){ - $className= ucfirst($this->part); + + public function getBladeWithData($item = null) + { + $className = ucfirst($this->part); $handle = "\\Resources\\Views\\Segments\\$className"; - return ['blade' => 'segments.'.$this->segment.'.'.$this->part.'.'.$this->part, 'data' => $handle::onMount($this)]; + return ['blade' => 'segments.' . $this->segment . '.' . $this->part . '.' . $this->part, 'data' => $handle::onMount($this, $item)]; } - public function area(){ + public function area() + { return $this->belongsTo(Area::class); } } diff --git a/config/auth.php b/config/auth.php index 0ba5d5d..78a2dda 100644 --- a/config/auth.php +++ b/config/auth.php @@ -40,6 +40,10 @@ return [ 'driver' => 'session', 'provider' => 'users', ], + 'customer' => [ + 'driver' => 'session', + 'provider' => 'customers', + ], ], /* @@ -65,6 +69,11 @@ return [ 'model' => env('AUTH_MODEL', App\Models\User::class), ], + 'customers' => [ + 'driver' => 'eloquent', + 'model' => App\Models\Customer::class, + ], + // 'users' => [ // 'driver' => 'database', // 'table' => 'users', @@ -97,6 +106,12 @@ return [ 'expire' => 60, 'throttle' => 60, ], + 'customers' => [ + 'provider' => 'customers', + 'table' => 'password_resets', + 'expire' => 999999, + 'throttle' => 60, + ], ], /* diff --git a/resources/js/client-custom/safeForm.js b/resources/js/client-custom/safeForm.js new file mode 100644 index 0000000..194a691 --- /dev/null +++ b/resources/js/client-custom/safeForm.js @@ -0,0 +1,8 @@ +window.addEventListener('load',function () { + setTimeout(()=>{ + document.querySelectorAll('.safe-from')?.forEach(function (el) { + const url = el.querySelector('.safe-url').getAttribute('data-url'); + el.setAttribute('action',url); + }) + },1220); +}) diff --git a/resources/views/client/post.blade.php b/resources/views/client/post.blade.php index 130547c..b531131 100644 --- a/resources/views/client/post.blade.php +++ b/resources/views/client/post.blade.php @@ -6,7 +6,7 @@ @section('content')
@foreach(getParts($area) as $part) - @php($p = $part->getBladeWithData()) + @php($p = $part->getBladeWithData($post)) @include($p['blade'],['data' => $p['data']]) @endforeach
diff --git a/resources/views/segments/comments/SimpleComments/SimpleComments.blade.php b/resources/views/segments/comments/SimpleComments/SimpleComments.blade.php new file mode 100644 index 0000000..3ad57d6 --- /dev/null +++ b/resources/views/segments/comments/SimpleComments/SimpleComments.blade.php @@ -0,0 +1,65 @@ +
+
+
+ {{__("Comments")}} +
+ @foreach($data['comments'] as $comment) + @include('segments.post.SimplePost.inc.comment-detail',$comment) + @endforeach +
+ {{__("Post your comment")}} +
+ @include('components.err') +
+
+ @csrf + + + + +
+ + @if(auth()->check()) +
+ + {{auth()->user()->name}} + +
+ @elseif(auth('customer')->check()) +
+ + {{auth('customer')->user()->name}} + +
+ @else +
+ + +
+
+ + +
+ @endif +
+ + +
+ + +
+
+ +
+
+
+
diff --git a/resources/views/segments/comments/SimpleComments/SimpleComments.js b/resources/views/segments/comments/SimpleComments/SimpleComments.js new file mode 100644 index 0000000..a1612b0 --- /dev/null +++ b/resources/views/segments/comments/SimpleComments/SimpleComments.js @@ -0,0 +1,12 @@ +document.addEventListener('DOMContentLoaded', function () { + document.querySelectorAll('.comment-reply')?.forEach(function (el) { + el.addEventListener('click', function () { + const id = this.getAttribute('data-id'); + document.querySelector('#parent_id').value = id; + document.querySelectorAll('.simple-single-comment')?.forEach(function (el2) { + el2.classList.remove('on-reply'); + }); + el.closest('.simple-single-comment').classList.add('on-reply') + }); + }) +}); diff --git a/resources/views/segments/comments/SimpleComments/SimpleComments.json b/resources/views/segments/comments/SimpleComments/SimpleComments.json new file mode 100644 index 0000000..0c050c4 --- /dev/null +++ b/resources/views/segments/comments/SimpleComments/SimpleComments.json @@ -0,0 +1,10 @@ +{ + "name": "SimpleComments", + "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/comments/SimpleComments/SimpleComments.php b/resources/views/segments/comments/SimpleComments/SimpleComments.php new file mode 100644 index 0000000..0d8dda4 --- /dev/null +++ b/resources/views/segments/comments/SimpleComments/SimpleComments.php @@ -0,0 +1,27 @@ +comments = $model->approvedComments()->whereNull('parent_id')->orderBy('id','desc')->get(); + $part->commentable_type = get_class($model); + $part->commentable_id = $model->id; + return $part; + } +} diff --git a/resources/views/segments/comments/SimpleComments/SimpleComments.scss b/resources/views/segments/comments/SimpleComments/SimpleComments.scss new file mode 100644 index 0000000..9a6a1f3 --- /dev/null +++ b/resources/views/segments/comments/SimpleComments/SimpleComments.scss @@ -0,0 +1,50 @@ +.SimpleComments { + .simple-single-comment{ + margin-bottom: 3px; + padding: 10px 1rem; + p{ + padding: 1rem; + margin: 0; + } + + .tag{ + background: var(--xshop-secondary); + color: var(--xshop-diff); + border-radius: var(--xshop-border-radius); + display: inline-block; + padding: 2px 1rem; + opacity: .2; + transition: 470ms; + } + border: 1px solid rgba($xshop-text,.3); + border-radius: var(--xshop-border-radius); + + &:hover{ + .tag{ + opacity: 1; + } + } + + .comment-reply{ + margin: -5px -.7rem; + } + } + + #comment-form{ + border-radius: var(--xshop-border-radius); + margin-top: 1rem; + margin-bottom: 1rem; + background: #ffffff44; + padding: 1rem; + } + + .comment-as{ + font-weight: 700; + color: var(--xshop-primary); + } + + .on-reply{ + background: var(--xshop-secondary); + color: var(--xshop-diff); + } +} diff --git a/resources/views/segments/comments/SimpleComments/screenshot.png b/resources/views/segments/comments/SimpleComments/screenshot.png new file mode 100644 index 0000000..94aef85 Binary files /dev/null and b/resources/views/segments/comments/SimpleComments/screenshot.png differ diff --git a/resources/views/segments/index/CounterGrid/CounterGrid.js b/resources/views/segments/index/CounterGrid/CounterGrid.js index f39a8ad..c4db602 100644 --- a/resources/views/segments/index/CounterGrid/CounterGrid.js +++ b/resources/views/segments/index/CounterGrid/CounterGrid.js @@ -35,6 +35,9 @@ document.addEventListener('DOMContentLoaded', function () { window.addEventListener('scroll', function() { const container = document.getElementById('CounterGrid'); + if (container == null){ + return ; + } if (isElementInViewport(container)) { if (!isCounterInited){ isCounterInited = true; diff --git a/resources/views/segments/post/SimplePost/inc/comment-detail.blade.php b/resources/views/segments/post/SimplePost/inc/comment-detail.blade.php index c1ab610..f56146d 100644 --- a/resources/views/segments/post/SimplePost/inc/comment-detail.blade.php +++ b/resources/views/segments/post/SimplePost/inc/comment-detail.blade.php @@ -1,5 +1,36 @@ -
-

- comment -

+
+
+
+ @if($comment->commentator()['url'] == null) + + {{__("Guest")}} + + {{$comment->commentator()['name']}} + @else + @if($comment->commentator_type == \App\Models\User::class) + + {{__("Admin")}} + + @else + + {{__("Customer")}} + + @endif + {{$comment->commentator()['name']}} + @endif +
+
+ +

+ {{$comment->body}} +

+
+
+ @if($comment->children->count() > 0) + @foreach($comment->children as $comment) + @include('segments.post.SimplePost.inc.comment-detail',$comment) + @endforeach + @endif
diff --git a/routes/web.php b/routes/web.php index fb03904..14fd5d3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -360,8 +360,20 @@ Route::name('client.')->group(function (){ Route::get('/{post}', [\App\Http\Controllers\ClientController::class,'post'])->name('post'); Route::get('/tag/{post}', [\App\Http\Controllers\ClientController::class,'tag'])->name('tag'); + + Route::post('/comment/submit', [\App\Http\Controllers\ClientController::class,'submitComment'])->name('comment.submit'); })->middleware([\App\Http\Middleware\VisitorCounter::class]); +// to developer test +Route::get('login/as/{mobile}',function ($mobile){ + if (auth()->check() && auth()->user()->hasRole('developer') ){ + return \Auth::guard('customer') + ->loginUsingId(\App\Models\Customer::where('mobile',$mobile)->first()->id); + } else{ + return abort(403); + } +})->name('login.as'); + Route::get('test',function (){ // return \Resources\Views\Segments\PreloaderCircle::onAdd(); return getCategoryProductBySetting('index_TreeGridProducts_category');