added contacts api
This commit is contained in:
parent
f6d2dea716
commit
f4f88c9037
|
|
@ -60,22 +60,12 @@ class ContactCrudController extends CrudController
|
|||
CRUD::setValidation(ContactRequest::class);
|
||||
|
||||
CRUD::field('name');
|
||||
CRUD::field('contacts')->type('repeatable')->fields([
|
||||
[ // Table
|
||||
'name' => 'contact',
|
||||
'label' => 'Contact',
|
||||
'type' => 'table',
|
||||
'entity_singular' => 'contact',
|
||||
'columns' => [
|
||||
'title' => 'Title',
|
||||
'phone' => 'Phone',
|
||||
'mail' => 'Mail',
|
||||
'fax' => 'Fax'
|
||||
],
|
||||
'max' => 2, // maximum rows allowed in the table
|
||||
'min' => 1, // minimum rows allowed in the table
|
||||
],
|
||||
])->new_item_label("Add contact");
|
||||
CRUD::field('contacts')->type('table')->columns([
|
||||
'title' => 'Title',
|
||||
'phone' => 'Phone',
|
||||
'mail' => 'Mail',
|
||||
'fax' => 'Fax'
|
||||
])->entity_singular('contact')->max(2)->min(1)->new_item_label("Add contact");
|
||||
|
||||
/**
|
||||
* Fields can be defined using the fluent syntax or array syntax:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Models\Contact;
|
||||
use App\Transformers\ContactTransformer;
|
||||
|
||||
class ContactController extends ApiController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$contacts = Contact::orderBy('lft', 'desc')->get();
|
||||
return $this->respondWithCollection($contacts, new ContactTransformer($this->locale));
|
||||
}
|
||||
}
|
||||
|
|
@ -12,5 +12,4 @@ class DocumentController extends ApiController
|
|||
$documents = Document::orderBy('lft', 'desc')->get();
|
||||
return $this->respondWithCollection($documents, new DocumentTransformer($this->locale));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,9 @@ use App\Transformers\CategoryTransformer;
|
|||
|
||||
class MultimediaCategoryController extends ApiController
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$categories = MultimediaCategory::orderBy('lft', 'desc')->get();
|
||||
return $this->respondWithCollection($categories, new CategoryTransformer($this->locale, 'media'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,5 +12,4 @@ class MultimediaController extends ApiController
|
|||
$medias = MultimediaCategory::where('id', $category)->with('medias')->get()->first()->medias;
|
||||
return $this->respondWithCollection($medias, new MediaTransformer());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,5 +18,4 @@ class TarifController extends ApiController
|
|||
}
|
||||
return $this->respondWithCollection($tarifs, new TarifTransformer($this->locale));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,8 +78,6 @@ class TradingsController extends ApiController
|
|||
return $this->errorNotFound();
|
||||
}
|
||||
return $this->errorWrongArgs();
|
||||
|
||||
|
||||
}
|
||||
function getPercentageDifference($new, $old){
|
||||
return (($new - $old) / abs($old)) * 100;
|
||||
|
|
|
|||
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Contact;
|
||||
use App\Http\Requests\StoreContactRequest;
|
||||
use App\Http\Requests\UpdateContactRequest;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\StoreContactRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreContactRequest $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Contact $contact
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Contact $contact)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Contact $contact
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Contact $contact)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\UpdateContactRequest $request
|
||||
* @param \App\Models\Contact $contact
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateContactRequest $request, Contact $contact)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Contact $contact
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Contact $contact)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Transformers;
|
||||
|
||||
use App\Models\Category;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class CategoryTransformer extends TransformerAbstract
|
||||
|
|
@ -18,13 +17,12 @@ class CategoryTransformer extends TransformerAbstract
|
|||
|
||||
public function transform($category)
|
||||
{
|
||||
|
||||
return $this->type == 'trading' ? [
|
||||
'id' => $category->id,
|
||||
'title' => $category->getTranslations('title', [$this->locale])[$this->locale],
|
||||
'title' => $category->getTranslations('title', [$this->locale])[$this->locale] ?? '-',
|
||||
] : [
|
||||
'id' => $category->id,
|
||||
'title' => $category->getTranslations('title', [$this->locale])[$this->locale],
|
||||
'title' => $category->getTranslations('title', [$this->locale])[$this->locale] ?? '-',
|
||||
'type' => $category->type,
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Transformers;
|
||||
|
||||
use App\Models\Contact;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class ContactTransformer extends TransformerAbstract
|
||||
{
|
||||
private $locale;
|
||||
|
||||
public function __construct($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
public function transform(Contact $contact)
|
||||
{
|
||||
$translatedContact = $contact->getTranslations('contacts',[$this->locale]);
|
||||
$contacts = $translatedContact ? json_decode($translatedContact[$this->locale], true) : [];
|
||||
return [
|
||||
'id' => $contact->id,
|
||||
'name' => $contact->getTranslations('name',[$this->locale])[$this->locale] ?? '-',
|
||||
'contacts' => $contacts,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -17,11 +17,12 @@ class DocumentTransformer extends TransformerAbstract
|
|||
|
||||
public function transform(Document $document)
|
||||
{
|
||||
$file = Str::replaceFirst('public/', '', $document->getTranslations('file',[$this->locale])[$this->locale]);
|
||||
$translatedFile = $document->getTranslations('file',[$this->locale]);
|
||||
$file = $translatedFile ? url(Str::replaceFirst('public/', '', $translatedFile[$this->locale])) : '-';
|
||||
return [
|
||||
'id' => $document->id,
|
||||
'title' => $document->getTranslations('title',[$this->locale]),
|
||||
'file' => url($file),
|
||||
'title' => $document->getTranslations('title',[$this->locale])[$this->locale] ?? '-',
|
||||
'file' => $file,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -18,9 +18,9 @@ class NewsTransformer extends TransformerAbstract
|
|||
{
|
||||
return [
|
||||
'id' => $news->id,
|
||||
'title' => $news->getTranslations('title', [$this->locale]),
|
||||
'short_description' => $news->getTranslations('short_description', [$this->locale]),
|
||||
'description' => $news->getTranslations('description', [$this->locale]),
|
||||
'title' => $news->getTranslations('title', [$this->locale])[$this->locale] ?? '-',
|
||||
'short_description' => $news->getTranslations('short_description', [$this->locale])[$this->locale] ?? '-',
|
||||
'description' => $news->getTranslations('description', [$this->locale])[$this->locale] ?? '-',
|
||||
'date' => $news->date,
|
||||
'image' => url($news->image),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ class TarifTransformer extends TransformerAbstract
|
|||
return [
|
||||
'id' => $tarif->id,
|
||||
'type' => $tarif->type,
|
||||
'title' => $tarif->getTranslations('title', [$this->locale]),
|
||||
'prices' => $tarif->getTranslations('prices', [$this->locale]),
|
||||
'title' => $tarif->getTranslations('title', [$this->locale])[$this->locale] ?? '-',
|
||||
'prices' => $tarif->getTranslations('prices', [$this->locale])[$this->locale] ?? [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ class TradingTransformer extends TransformerAbstract
|
|||
{
|
||||
private $type;
|
||||
|
||||
public function __construct($type='')
|
||||
public function __construct($type = '')
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'locale' => 'tm',
|
||||
'locale' => 'ru',
|
||||
'locales' => ['en','ru','tm'],
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ class CreateContactsTable extends Migration
|
|||
$table->id();
|
||||
$table->text('name');
|
||||
$table->longText('contacts');
|
||||
$table->integer('parent_id')->default(0)->nullable();
|
||||
$table->integer('lft')->default(0);
|
||||
$table->integer('rgt')->default(0);
|
||||
$table->integer('depth')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Http\Controllers\Api\ImportController;
|
|||
use App\Http\Controllers\Api\TradingsController;
|
||||
use App\Http\Controllers\Api\NewsController;
|
||||
use App\Http\Controllers\Api\CategoryController;
|
||||
use App\Http\Controllers\Api\ContactController;
|
||||
use App\Http\Controllers\Api\DocumentController;
|
||||
use App\Http\Controllers\Api\TarifController;
|
||||
use App\Http\Controllers\Api\MultimediaCategoryController;
|
||||
|
|
@ -34,9 +35,12 @@ Route::get('other-filters', [FiltersController::class, 'otherFilters']);
|
|||
Route::get('categories', [CategoryController::class, 'index']);
|
||||
Route::get('tradings', [TradingsController::class, 'index']);
|
||||
Route::get('categories/{id}/tradings', [TradingsController::class, 'selectedTradings']);
|
||||
Route::get('news', [NewsController::class, 'index']);
|
||||
Route::get('documents', [DocumentController::class, 'index']);
|
||||
Route::get('tariffs', [TarifController::class, 'index']);
|
||||
|
||||
Route::get('media/categories', [MultimediaCategoryController::class, 'index']);
|
||||
Route::get('medias/{category}', [MultimediaController::class, 'index']);
|
||||
|
||||
Route::get('news', [NewsController::class, 'index']);
|
||||
Route::get('documents', [DocumentController::class, 'index']);
|
||||
Route::get('tariffs', [TarifController::class, 'index']);
|
||||
Route::get('contacts', [ContactController::class, 'index']);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue