added api contact us
This commit is contained in:
parent
ed1f5f5846
commit
178e1c0819
|
|
@ -0,0 +1,105 @@
|
||||||
|
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
|
||||||
|
|
||||||
|
use Cms\Classes\Controller;
|
||||||
|
use BackendMenu;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Tps\Tps\Models\ContactUs;
|
||||||
|
class ContactUsController extends Controller
|
||||||
|
{
|
||||||
|
protected $ContactUs;
|
||||||
|
|
||||||
|
protected $helpers;
|
||||||
|
|
||||||
|
public function __construct(ContactUs $ContactUs, Helpers $helpers)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->ContactUs = $ContactUs;
|
||||||
|
$this->helpers = $helpers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index(){
|
||||||
|
|
||||||
|
$data = $this->ContactUs->all()->toArray();
|
||||||
|
|
||||||
|
$baseUrl = url('/storage/app/media');
|
||||||
|
|
||||||
|
foreach ($data as &$project) {
|
||||||
|
$project['image'] = $baseUrl . $project['image'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id){
|
||||||
|
|
||||||
|
$data = $this->ContactUs::find($id);
|
||||||
|
|
||||||
|
if ($data){
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]);
|
||||||
|
} else {
|
||||||
|
$this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request){
|
||||||
|
|
||||||
|
$arr = $request->all();
|
||||||
|
|
||||||
|
while ( $data = current($arr)) {
|
||||||
|
$this->ContactUs->{key($arr)} = $data;
|
||||||
|
next($arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
$validation = Validator::make($request->all(), $this->ContactUs->rules);
|
||||||
|
|
||||||
|
if( $validation->passes() ){
|
||||||
|
$this->ContactUs->save();
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(201, 'created', ['id' => $this->ContactUs->id]);
|
||||||
|
}else{
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validation->errors() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id, Request $request){
|
||||||
|
|
||||||
|
$status = $this->ContactUs->where('id',$id)->update($data);
|
||||||
|
|
||||||
|
if( $status ){
|
||||||
|
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been updated successfully.');
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(400, 'bad request', 'Error, data failed to update.');
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id){
|
||||||
|
|
||||||
|
$this->ContactUs->where('id',$id)->delete();
|
||||||
|
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($id){
|
||||||
|
|
||||||
|
$this->ContactUs->where('id',$id)->delete();
|
||||||
|
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getAfterFilters() {return [];}
|
||||||
|
public static function getBeforeFilters() {return [];}
|
||||||
|
public static function getMiddleware() {return [];}
|
||||||
|
public function callAction($method, $parameters=false) {
|
||||||
|
return call_user_func_array(array($this, $method), $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -18,3 +18,5 @@ Route::resource('api/v1/mainServices', 'AhmadFatoni\ApiGenerator\Controllers\API
|
||||||
Route::get('api/v1/mainServices/{id}/delete', ['as' => 'api/v1/mainServices.delete', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\API\MainServicesController@destroy']);
|
Route::get('api/v1/mainServices/{id}/delete', ['as' => 'api/v1/mainServices.delete', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\API\MainServicesController@destroy']);
|
||||||
Route::resource('api/v1/contact', 'AhmadFatoni\ApiGenerator\Controllers\API\ContactController', ['except' => ['destroy', 'create', 'edit']]);
|
Route::resource('api/v1/contact', 'AhmadFatoni\ApiGenerator\Controllers\API\ContactController', ['except' => ['destroy', 'create', 'edit']]);
|
||||||
Route::get('api/v1/contact/{id}/delete', ['as' => 'api/v1/contact.delete', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\API\ContactController@destroy']);
|
Route::get('api/v1/contact/{id}/delete', ['as' => 'api/v1/contact.delete', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\API\ContactController@destroy']);
|
||||||
|
Route::resource('api/v1/contactUs', 'AhmadFatoni\ApiGenerator\Controllers\API\ContactUsController', ['except' => ['destroy', 'create', 'edit']]);
|
||||||
|
Route::get('api/v1/contactUs/{id}/delete', ['as' => 'api/v1/contactUs.delete', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\API\ContactUsController@destroy']);
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php namespace Tps\Tps\Controllers;
|
||||||
|
|
||||||
|
use Backend;
|
||||||
|
use BackendMenu;
|
||||||
|
use Backend\Classes\Controller;
|
||||||
|
|
||||||
|
class ContactUsController extends Controller
|
||||||
|
{
|
||||||
|
public $implement = [
|
||||||
|
\Backend\Behaviors\FormController::class,
|
||||||
|
\Backend\Behaviors\ListController::class
|
||||||
|
];
|
||||||
|
|
||||||
|
public $formConfig = 'config_form.yaml';
|
||||||
|
public $listConfig = 'config_list.yaml';
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
BackendMenu::setContext('Tps.Tps', 'main-menu-item', 'side-menu-item7');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<div data-control="toolbar">
|
||||||
|
<a
|
||||||
|
href="<?= Backend::url('tps/tps/contactuscontroller/create') ?>"
|
||||||
|
class="btn btn-primary oc-icon-plus">
|
||||||
|
<?= e(trans('backend::lang.form.create')) ?>
|
||||||
|
</a>
|
||||||
|
<button
|
||||||
|
class="btn btn-default oc-icon-trash-o"
|
||||||
|
data-request="onDelete"
|
||||||
|
data-request-confirm="<?= e(trans('backend::lang.list.delete_selected_confirm')) ?>"
|
||||||
|
data-list-checked-trigger
|
||||||
|
data-list-checked-request
|
||||||
|
data-stripe-load-indicator>
|
||||||
|
<?= e(trans('backend::lang.list.delete_selected')) ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
name: ContactUsController
|
||||||
|
form: $/tps/tps/models/contactus/fields.yaml
|
||||||
|
modelClass: Tps\Tps\Models\ContactUs
|
||||||
|
defaultRedirect: tps/tps/contactuscontroller
|
||||||
|
create:
|
||||||
|
redirect: 'tps/tps/contactuscontroller/update/:id'
|
||||||
|
redirectClose: tps/tps/contactuscontroller
|
||||||
|
update:
|
||||||
|
redirect: tps/tps/contactuscontroller
|
||||||
|
redirectClose: tps/tps/contactuscontroller
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
list: $/tps/tps/models/contactus/columns.yaml
|
||||||
|
modelClass: Tps\Tps\Models\ContactUs
|
||||||
|
title: ContactUsController
|
||||||
|
noRecordsMessage: 'backend::lang.list.no_records'
|
||||||
|
showSetup: true
|
||||||
|
showCheckboxes: true
|
||||||
|
recordsPerPage: 20
|
||||||
|
toolbar:
|
||||||
|
buttons: list_toolbar
|
||||||
|
search:
|
||||||
|
prompt: 'backend::lang.list.search_prompt'
|
||||||
|
recordUrl: 'tps/tps/contactuscontroller/update/:id'
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php Block::put('breadcrumb') ?>
|
||||||
|
<ul>
|
||||||
|
<li><a href="<?= Backend::url('tps/tps/contactuscontroller') ?>">ContactUsController</a></li>
|
||||||
|
<li><?= e($this->pageTitle) ?></li>
|
||||||
|
</ul>
|
||||||
|
<?php Block::endPut() ?>
|
||||||
|
|
||||||
|
<?php if (!$this->fatalError): ?>
|
||||||
|
|
||||||
|
<?= Form::open(['class' => 'layout']) ?>
|
||||||
|
|
||||||
|
<div class="layout-row">
|
||||||
|
<?= $this->formRender() ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-buttons">
|
||||||
|
<div class="loading-indicator-container">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
data-request="onSave"
|
||||||
|
data-hotkey="ctrl+s, cmd+s"
|
||||||
|
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
|
||||||
|
class="btn btn-primary">
|
||||||
|
<?= e(trans('backend::lang.form.create')) ?>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-request="onSave"
|
||||||
|
data-request-data="close:1"
|
||||||
|
data-hotkey="ctrl+enter, cmd+enter"
|
||||||
|
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
|
||||||
|
class="btn btn-default">
|
||||||
|
<?= e(trans('backend::lang.form.create_and_close')) ?>
|
||||||
|
</button>
|
||||||
|
<span class="btn-text">
|
||||||
|
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('tps/tps/contactuscontroller') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?= Form::close() ?>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
|
||||||
|
<p><a href="<?= Backend::url('tps/tps/contactuscontroller') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
|
||||||
|
<?php endif ?>
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<?= $this->listRender() ?>
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php Block::put('breadcrumb') ?>
|
||||||
|
<ul>
|
||||||
|
<li><a href="<?= Backend::url('tps/tps/contactuscontroller') ?>">ContactUsController</a></li>
|
||||||
|
<li><?= e($this->pageTitle) ?></li>
|
||||||
|
</ul>
|
||||||
|
<?php Block::endPut() ?>
|
||||||
|
|
||||||
|
<?php if (!$this->fatalError): ?>
|
||||||
|
|
||||||
|
<div class="form-preview">
|
||||||
|
<?= $this->formRenderPreview() ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
<p class="flash-message static error"><?= e($this->fatalError) ?></p>
|
||||||
|
<?php endif ?>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a href="<?= Backend::url('tps/tps/contactuscontroller') ?>" class="btn btn-default oc-icon-chevron-left">
|
||||||
|
<?= e(trans('backend::lang.form.return_to_list')) ?>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php Block::put('breadcrumb') ?>
|
||||||
|
<ul>
|
||||||
|
<li><a href="<?= Backend::url('tps/tps/contactuscontroller') ?>">ContactUsController</a></li>
|
||||||
|
<li><?= e($this->pageTitle) ?></li>
|
||||||
|
</ul>
|
||||||
|
<?php Block::endPut() ?>
|
||||||
|
|
||||||
|
<?php if (!$this->fatalError): ?>
|
||||||
|
|
||||||
|
<?= Form::open(['class' => 'layout']) ?>
|
||||||
|
|
||||||
|
<div class="layout-row">
|
||||||
|
<?= $this->formRender() ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-buttons">
|
||||||
|
<div class="loading-indicator-container">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
data-request="onSave"
|
||||||
|
data-request-data="redirect:0"
|
||||||
|
data-hotkey="ctrl+s, cmd+s"
|
||||||
|
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
|
||||||
|
class="btn btn-primary">
|
||||||
|
<?= e(trans('backend::lang.form.save')) ?>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-request="onSave"
|
||||||
|
data-request-data="close:1"
|
||||||
|
data-hotkey="ctrl+enter, cmd+enter"
|
||||||
|
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
|
||||||
|
class="btn btn-default">
|
||||||
|
<?= e(trans('backend::lang.form.save_and_close')) ?>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="oc-icon-trash-o btn-icon danger pull-right"
|
||||||
|
data-request="onDelete"
|
||||||
|
data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
|
||||||
|
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<span class="btn-text">
|
||||||
|
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('tps/tps/contactuscontroller') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?= Form::close() ?>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
|
||||||
|
<p><a href="<?= Backend::url('tps/tps/contactuscontroller') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
|
||||||
|
<?php endif ?>
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php namespace Tps\Tps\Models;
|
||||||
|
|
||||||
|
use Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Model
|
||||||
|
*/
|
||||||
|
class ContactUs extends Model
|
||||||
|
{
|
||||||
|
use \October\Rain\Database\Traits\Validation;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string table in the database used by the model.
|
||||||
|
*/
|
||||||
|
public $table = 'tps_tps_contact_us';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array rules for validation.
|
||||||
|
*/
|
||||||
|
public $rules = [
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
columns:
|
||||||
|
id:
|
||||||
|
label: id
|
||||||
|
type: number
|
||||||
|
title:
|
||||||
|
label: title
|
||||||
|
type: text
|
||||||
|
created_at:
|
||||||
|
label: created_at
|
||||||
|
type: datetime
|
||||||
|
updated_at:
|
||||||
|
label: updated_at
|
||||||
|
type: datetime
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
fields:
|
||||||
|
title:
|
||||||
|
label: Title
|
||||||
|
span: auto
|
||||||
|
type: text
|
||||||
|
text:
|
||||||
|
label: Text
|
||||||
|
size: small
|
||||||
|
span: auto
|
||||||
|
type: textarea
|
||||||
|
image:
|
||||||
|
label: Image
|
||||||
|
mode: image
|
||||||
|
thumbOptions:
|
||||||
|
mode: crop
|
||||||
|
extension: auto
|
||||||
|
span: auto
|
||||||
|
type: mediafinder
|
||||||
|
|
@ -34,6 +34,10 @@ navigation:
|
||||||
label: 'Main Services'
|
label: 'Main Services'
|
||||||
url: tps/tps/mainservicescontroller
|
url: tps/tps/mainservicescontroller
|
||||||
icon: icon-signal
|
icon: icon-signal
|
||||||
|
side-menu-item7:
|
||||||
|
label: 'Contact us'
|
||||||
|
url: tps/tps/contactuscontroller
|
||||||
|
icon: icon-comments-o
|
||||||
main-menu-item2:
|
main-menu-item2:
|
||||||
label: Contacts
|
label: Contacts
|
||||||
url: tps/tps/contactscontroller
|
url: tps/tps/contactscontroller
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php namespace Tps\Tps\Updates;
|
||||||
|
|
||||||
|
use Schema;
|
||||||
|
use October\Rain\Database\Updates\Migration;
|
||||||
|
|
||||||
|
class BuilderTableCreateTpsTpsContactUs extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('tps_tps_contact_us', function($table)
|
||||||
|
{
|
||||||
|
$table->increments('id')->unsigned();
|
||||||
|
$table->string('title');
|
||||||
|
$table->text('text');
|
||||||
|
$table->string('image');
|
||||||
|
$table->timestamp('created_at')->nullable();
|
||||||
|
$table->timestamp('updated_at')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('tps_tps_contact_us');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -48,3 +48,6 @@ v1.0.16:
|
||||||
v1.0.17:
|
v1.0.17:
|
||||||
- 'Updated table tps_tps_cartoons'
|
- 'Updated table tps_tps_cartoons'
|
||||||
- builder_table_update_tps_tps_cartoons_3.php
|
- builder_table_update_tps_tps_cartoons_3.php
|
||||||
|
v1.0.18:
|
||||||
|
- 'Created table tps_tps_contact_us'
|
||||||
|
- builder_table_create_tps_tps_contact_us.php
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue