mirror of https://github.com/4xmen/xshop.git
added contact controller
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 [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue