added contact controller

pull/44/head
A1Gard 5 months ago
parent 0e338e44a1
commit 494c642956

@ -0,0 +1,132 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\ContactSaveRequest;
use App\Models\Access;
use App\Models\Contact;
use Illuminate\Http\Request;
use App\Helper;
use Illuminate\Support\Facades\Mail;
use function App\Helpers\hasCreateRoute;
class ContactController extends XController
{
// protected $_MODEL_ = Contact::class;
// protected $SAVE_REQUEST = ContactSaveRequest::class;
protected $cols = ['name','subject','mobile','email',"created_at",'is_answered'];
protected $extra_cols = ['id','hash'];
protected $searchable = ['name','subject','mobile','email','body'];
protected $listView = 'admin.contacts.contact-list';
protected $formView = 'admin.contacts.contact-form';
protected $buttons = [
// 'edit' =>
// ['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 .= '<hr>'. __("Answer: <br>").$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')]);
}
}

@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ContactSaveRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}

@ -13,11 +13,13 @@ return new class extends Migration
{ {
Schema::create('contacts', function (Blueprint $table) { Schema::create('contacts', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('full_name'); $table->string('name');
$table->string('email'); $table->string('email');
$table->string('subject')->nullable(); $table->string('subject')->nullable();
$table->string('phone',15); $table->string('mobile',15);
$table->string('hash',32)->unique()->nullable();
$table->text('body'); $table->text('body');
$table->boolean('is_answered')->default(false);
$table->timestamps(); $table->timestamps();
}); });
} }

@ -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')
<div class="row">
<div class="col-lg-3">
@include('components.err')
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-message-3-line"></i>
{{__("Tips")}}
</h3>
<ul>
<li>
{{__("Recommends")}}
</li>
</ul>
</div>
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form ">
<h1>
@if(isset($item))
{{__("Edit contact")}} [{{$item->id}}]
@else
{{__("Add new contact")}}
@endif
</h1>
</div>
</div>
</div>
@endsection

@ -0,0 +1,15 @@
@extends('admin.templates.panel-list-template')
@section('list-title')
<i class="ri-user-3-line"></i>
{{__("Contacts list")}}
@endsection
@section('title')
{{__("Contacts list")}} -
@endsection
@section('filter')
{{-- Other filters --}}
@endsection
@section('bulk')
{{-- <option value="-"> - </option> --}}
@endsection

@ -0,0 +1,69 @@
@extends('layouts.app')
@section('content')
<table class="table table-bordered table-striped mb-4">
<tr>
<th>
{{__("Date")}}
</th>
<td>
{{$item->created_at->ldate('Y/m/d H:i')}}
</td>
</tr>
<tr>
<th>
{{__("Subject")}}
</th>
<td>
{{($item->subject)}}
</td>
</tr>
<tr>
<th>
{{__("Name and lastname")}}
</th>
<td>
{{($item->name)}}
</td>
</tr>
<tr>
<th>
{{__("Mobile")}}
</th>
<td>
{{($item->mobile)}}
</td>
</tr>
<tr>
<th>
{{__("Email")}}
</th>
<td>
{{($item->email)}}
</td>
</tr>
<tr>
<th>
{{__("Question/Message")}}
</th>
<td>
{!! $item->body !!}
</td>
</tr>
</table>
<form action="{{route('admin.contact.reply',$item->hash)}}" class="mt-4" method="post">
@csrf
<div class="form-group">
<h4 style="text-align: center;">
<label for="bodya">
{{__("Post reply")}}
</label>
</h4>
<textarea type="" id="bodya" name="bodya" rows="10" placeholder="{{__("Reply message...")}}" class="form-control ckeditorx"></textarea>
</div>
<button type="submit" class="btn btn-primary w-100 my-4" >
{{__('Reply')}}
</button>
</form>
@endsection

@ -168,7 +168,7 @@
</a> </a>
</li> </li>
<li> <li>
<a href=""> <a href="{{route('admin.contact.index')}}">
<i class="ri-mail-unread-fill"></i> <i class="ri-mail-unread-fill"></i>
{{__("Contact us")}} {{__("Contact us")}}
</a> </a>

@ -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::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::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( Route::prefix('transports')->name('transport.')->group(
function () { function () {
@ -240,5 +250,12 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group(
}); });
Route::get('test',function (){ 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(); return \App\Helpers\PersianFaker::color();
}); });

Loading…
Cancel
Save