From 494c642956ca7722ed46fdbceb898ffb1ebd86a9 Mon Sep 17 00:00:00 2001 From: A1Gard Date: Tue, 25 Jun 2024 04:40:12 +0330 Subject: [PATCH] added contact controller --- .../Controllers/Admin/ContactController.php | 132 ++++++++++++++++++ app/Http/Requests/ContactSaveRequest.php | 28 ++++ ...024_05_07_133943_create_contacts_table.php | 6 +- .../admin/contacts/contact-form.blade.php | 42 ++++++ .../admin/contacts/contact-list.blade.php | 15 ++ .../admin/contacts/contact-show.blade.php | 69 +++++++++ .../components/panel-side-navbar.blade.php | 2 +- routes/web.php | 17 +++ 8 files changed, 308 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/Admin/ContactController.php create mode 100644 app/Http/Requests/ContactSaveRequest.php create mode 100644 resources/views/admin/contacts/contact-form.blade.php create mode 100644 resources/views/admin/contacts/contact-list.blade.php create mode 100644 resources/views/admin/contacts/contact-show.blade.php diff --git a/app/Http/Controllers/Admin/ContactController.php b/app/Http/Controllers/Admin/ContactController.php new file mode 100644 index 0000000..b91dfab --- /dev/null +++ b/app/Http/Controllers/Admin/ContactController.php @@ -0,0 +1,132 @@ + +// ['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'], + 'show' => + ['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'], + 'destroy' => + ['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'], + ]; + + + public function __construct() + { + parent::__construct(Contact::class, ContactSaveRequest::class); + } + + /** + * @param $contact Contact + * @param $request ContactSaveRequest + * @return Contact + */ + public function save($contact, $request) + { + + $contact->save(); + return $contact; + + } + + + public function show( $hash){ + $item = Contact::whereHash($hash)->firstOrFail(); + return view('admin.contacts.contact-show',compact('item')); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + // + return view($this->formView); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(Contact $item) + { + // + return view($this->formView, compact('item')); + } + + public function bulk(Request $request) + { + +// dd($request->all()); + $data = explode('.', $request->input('action')); + $action = $data[0]; + $ids = $request->input('id'); + switch ($action) { + case 'delete': + $msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]); + $this->_MODEL_::destroy($ids); + break; + + default: + $msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]); + } + + return $this->do_bulk($msg, $action, $ids); + } + + public function destroy(Contact $item) + { + return parent::delete($item); + } + + + public function update(Request $request, Contact $item) + { + return $this->bringUp($request, $item); + } + + public function reply(Request $request, Contact $item) + { + $body = $request->bodya; + $item->is_answered = true; + $item->body .= '
'. __("Answer:
").$body; + $item->save(); + + Mail::raw($body, function ($message) use ($item){ + + $message->from(getSetting('email'),config('app.name')); + $message->to($item->email); + $message->subject('reply:',config('app.name', 'xshop') .' پاسخ تماس با '); + }); + logAdmin(__METHOD__,Contact::class,$item->id); + + return redirect()->back()->with(['message' => __('Your Email sent')]); + } + + +} diff --git a/app/Http/Requests/ContactSaveRequest.php b/app/Http/Requests/ContactSaveRequest.php new file mode 100644 index 0000000..651b081 --- /dev/null +++ b/app/Http/Requests/ContactSaveRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2024_05_07_133943_create_contacts_table.php b/database/migrations/2024_05_07_133943_create_contacts_table.php index 22f9fae..802aac3 100644 --- a/database/migrations/2024_05_07_133943_create_contacts_table.php +++ b/database/migrations/2024_05_07_133943_create_contacts_table.php @@ -13,11 +13,13 @@ return new class extends Migration { Schema::create('contacts', function (Blueprint $table) { $table->id(); - $table->string('full_name'); + $table->string('name'); $table->string('email'); $table->string('subject')->nullable(); - $table->string('phone',15); + $table->string('mobile',15); + $table->string('hash',32)->unique()->nullable(); $table->text('body'); + $table->boolean('is_answered')->default(false); $table->timestamps(); }); } diff --git a/resources/views/admin/contacts/contact-form.blade.php b/resources/views/admin/contacts/contact-form.blade.php new file mode 100644 index 0000000..771972d --- /dev/null +++ b/resources/views/admin/contacts/contact-form.blade.php @@ -0,0 +1,42 @@ +@extends('admin.templates.panel-form-template') +@section('title') + @if(isset($item)) + {{__("Edit contact")}} [{{$item->id}}] + @else + {{__("Add new contact")}} + @endif - +@endsection +@section('form') + +
+
+ + @include('components.err') +
+

+ + {{__("Tips")}} +

+
    +
  • + {{__("Recommends")}} +
  • +
+
+ +
+
+
+ +

+ @if(isset($item)) + {{__("Edit contact")}} [{{$item->id}}] + @else + {{__("Add new contact")}} + @endif +

+ +
+
+
+@endsection diff --git a/resources/views/admin/contacts/contact-list.blade.php b/resources/views/admin/contacts/contact-list.blade.php new file mode 100644 index 0000000..3ff3434 --- /dev/null +++ b/resources/views/admin/contacts/contact-list.blade.php @@ -0,0 +1,15 @@ +@extends('admin.templates.panel-list-template') + +@section('list-title') + + {{__("Contacts list")}} +@endsection +@section('title') + {{__("Contacts list")}} - +@endsection +@section('filter') + {{-- Other filters --}} +@endsection +@section('bulk') + {{-- --}} +@endsection diff --git a/resources/views/admin/contacts/contact-show.blade.php b/resources/views/admin/contacts/contact-show.blade.php new file mode 100644 index 0000000..b02af21 --- /dev/null +++ b/resources/views/admin/contacts/contact-show.blade.php @@ -0,0 +1,69 @@ +@extends('layouts.app') +@section('content') + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {{__("Date")}} + + {{$item->created_at->ldate('Y/m/d H:i')}} +
+ {{__("Subject")}} + + {{($item->subject)}} +
+ {{__("Name and lastname")}} + + {{($item->name)}} +
+ {{__("Mobile")}} + + {{($item->mobile)}} +
+ {{__("Email")}} + + {{($item->email)}} +
+ {{__("Question/Message")}} + + {!! $item->body !!} +
+ +
+ @csrf +
+

+ +

+ +
+ +
+@endsection diff --git a/resources/views/components/panel-side-navbar.blade.php b/resources/views/components/panel-side-navbar.blade.php index 0e38446..9826df3 100644 --- a/resources/views/components/panel-side-navbar.blade.php +++ b/resources/views/components/panel-side-navbar.blade.php @@ -168,7 +168,7 @@
  • - + {{__("Contact us")}} diff --git a/routes/web.php b/routes/web.php index 7977632..552dad9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -74,6 +74,16 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group( Route::get('delete/{item}', [\App\Http\Controllers\Admin\TicketController::class, 'destroy'])->name('destroy'); Route::post('bulk', [\App\Http\Controllers\Admin\TicketController::class, "bulk"])->name('bulk'); }); + Route::prefix('contacts')->name('contact.')->group( + function () { + Route::get('', [\App\Http\Controllers\Admin\ContactController::class, 'index'])->name('index'); +// Route::get('create', [\App\Http\Controllers\Admin\TicketController::class, 'create'])->name('create'); + Route::post('store', [\App\Http\Controllers\Admin\ContactController::class, 'store'])->name('store'); + Route::get('show/{item}', [\App\Http\Controllers\Admin\ContactController::class, 'show'])->name('show'); + Route::post('reply/{item}', [\App\Http\Controllers\Admin\ContactController::class, 'reply'])->name('reply'); + Route::get('delete/{item}', [\App\Http\Controllers\Admin\ContactController::class, 'destroy'])->name('destroy'); + Route::post('bulk', [\App\Http\Controllers\Admin\ContactController::class, "bulk"])->name('bulk'); + }); Route::prefix('transports')->name('transport.')->group( function () { @@ -240,5 +250,12 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group( }); Route::get('test',function (){ + $c = new \App\Models\Contact(); + $c->name = 'mamali'; + $c->email = 'mamali@yahoo.com'; + $c->mobile = '091212344557'; + $c->body = 'test test contact'; + $c->subject = ' this a subject'; + $c->save(); return \App\Helpers\PersianFaker::color(); });