added contacts api

This commit is contained in:
Amanmyrat 2022-12-06 10:30:38 +05:00
parent f6d2dea716
commit f4f88c9037
21 changed files with 72 additions and 126 deletions

View File

@ -60,22 +60,12 @@ class ContactCrudController extends CrudController
CRUD::setValidation(ContactRequest::class); CRUD::setValidation(ContactRequest::class);
CRUD::field('name'); CRUD::field('name');
CRUD::field('contacts')->type('repeatable')->fields([ CRUD::field('contacts')->type('table')->columns([
[ // Table
'name' => 'contact',
'label' => 'Contact',
'type' => 'table',
'entity_singular' => 'contact',
'columns' => [
'title' => 'Title', 'title' => 'Title',
'phone' => 'Phone', 'phone' => 'Phone',
'mail' => 'Mail', 'mail' => 'Mail',
'fax' => 'Fax' 'fax' => 'Fax'
], ])->entity_singular('contact')->max(2)->min(1)->new_item_label("Add contact");
'max' => 2, // maximum rows allowed in the table
'min' => 1, // minimum rows allowed in the table
],
])->new_item_label("Add contact");
/** /**
* Fields can be defined using the fluent syntax or array syntax: * Fields can be defined using the fluent syntax or array syntax:

View File

@ -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));
}
}

View File

@ -12,5 +12,4 @@ class DocumentController extends ApiController
$documents = Document::orderBy('lft', 'desc')->get(); $documents = Document::orderBy('lft', 'desc')->get();
return $this->respondWithCollection($documents, new DocumentTransformer($this->locale)); return $this->respondWithCollection($documents, new DocumentTransformer($this->locale));
} }
} }

View File

@ -8,11 +8,9 @@ use App\Transformers\CategoryTransformer;
class MultimediaCategoryController extends ApiController class MultimediaCategoryController extends ApiController
{ {
public function index() public function index()
{ {
$categories = MultimediaCategory::orderBy('lft', 'desc')->get(); $categories = MultimediaCategory::orderBy('lft', 'desc')->get();
return $this->respondWithCollection($categories, new CategoryTransformer($this->locale, 'media')); return $this->respondWithCollection($categories, new CategoryTransformer($this->locale, 'media'));
} }
} }

View File

@ -12,5 +12,4 @@ class MultimediaController extends ApiController
$medias = MultimediaCategory::where('id', $category)->with('medias')->get()->first()->medias; $medias = MultimediaCategory::where('id', $category)->with('medias')->get()->first()->medias;
return $this->respondWithCollection($medias, new MediaTransformer()); return $this->respondWithCollection($medias, new MediaTransformer());
} }
} }

View File

@ -18,5 +18,4 @@ class TarifController extends ApiController
} }
return $this->respondWithCollection($tarifs, new TarifTransformer($this->locale)); return $this->respondWithCollection($tarifs, new TarifTransformer($this->locale));
} }
} }

View File

@ -78,8 +78,6 @@ class TradingsController extends ApiController
return $this->errorNotFound(); return $this->errorNotFound();
} }
return $this->errorWrongArgs(); return $this->errorWrongArgs();
} }
function getPercentageDifference($new, $old){ function getPercentageDifference($new, $old){
return (($new - $old) / abs($old)) * 100; return (($new - $old) / abs($old)) * 100;

View File

@ -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)
{
//
}
}

View File

@ -2,7 +2,6 @@
namespace App\Transformers; namespace App\Transformers;
use App\Models\Category;
use League\Fractal\TransformerAbstract; use League\Fractal\TransformerAbstract;
class CategoryTransformer extends TransformerAbstract class CategoryTransformer extends TransformerAbstract
@ -18,13 +17,12 @@ class CategoryTransformer extends TransformerAbstract
public function transform($category) public function transform($category)
{ {
return $this->type == 'trading' ? [ return $this->type == 'trading' ? [
'id' => $category->id, 'id' => $category->id,
'title' => $category->getTranslations('title', [$this->locale])[$this->locale], 'title' => $category->getTranslations('title', [$this->locale])[$this->locale] ?? '-',
] : [ ] : [
'id' => $category->id, 'id' => $category->id,
'title' => $category->getTranslations('title', [$this->locale])[$this->locale], 'title' => $category->getTranslations('title', [$this->locale])[$this->locale] ?? '-',
'type' => $category->type, 'type' => $category->type,
]; ];
} }

View File

@ -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,
];
}
}

View File

@ -17,11 +17,12 @@ class DocumentTransformer extends TransformerAbstract
public function transform(Document $document) 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 [ return [
'id' => $document->id, 'id' => $document->id,
'title' => $document->getTranslations('title',[$this->locale]), 'title' => $document->getTranslations('title',[$this->locale])[$this->locale] ?? '-',
'file' => url($file), 'file' => $file,
]; ];
} }
} }

View File

@ -18,9 +18,9 @@ class NewsTransformer extends TransformerAbstract
{ {
return [ return [
'id' => $news->id, 'id' => $news->id,
'title' => $news->getTranslations('title', [$this->locale]), 'title' => $news->getTranslations('title', [$this->locale])[$this->locale] ?? '-',
'short_description' => $news->getTranslations('short_description', [$this->locale]), 'short_description' => $news->getTranslations('short_description', [$this->locale])[$this->locale] ?? '-',
'description' => $news->getTranslations('description', [$this->locale]), 'description' => $news->getTranslations('description', [$this->locale])[$this->locale] ?? '-',
'date' => $news->date, 'date' => $news->date,
'image' => url($news->image), 'image' => url($news->image),
]; ];

View File

@ -19,8 +19,8 @@ class TarifTransformer extends TransformerAbstract
return [ return [
'id' => $tarif->id, 'id' => $tarif->id,
'type' => $tarif->type, 'type' => $tarif->type,
'title' => $tarif->getTranslations('title', [$this->locale]), 'title' => $tarif->getTranslations('title', [$this->locale])[$this->locale] ?? '-',
'prices' => $tarif->getTranslations('prices', [$this->locale]), 'prices' => $tarif->getTranslations('prices', [$this->locale])[$this->locale] ?? [],
]; ];
} }
} }

0
bootstrap/cache/packages.php vendored Executable file → Normal file
View File

0
bootstrap/cache/services.php vendored Executable file → Normal file
View File

View File

@ -82,7 +82,7 @@ return [
| |
*/ */
'locale' => 'tm', 'locale' => 'ru',
'locales' => ['en','ru','tm'], 'locales' => ['en','ru','tm'],
/* /*

View File

@ -17,6 +17,10 @@ class CreateContactsTable extends Migration
$table->id(); $table->id();
$table->text('name'); $table->text('name');
$table->longText('contacts'); $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(); $table->timestamps();
}); });
} }

View File

@ -8,6 +8,7 @@ use App\Http\Controllers\Api\ImportController;
use App\Http\Controllers\Api\TradingsController; use App\Http\Controllers\Api\TradingsController;
use App\Http\Controllers\Api\NewsController; use App\Http\Controllers\Api\NewsController;
use App\Http\Controllers\Api\CategoryController; use App\Http\Controllers\Api\CategoryController;
use App\Http\Controllers\Api\ContactController;
use App\Http\Controllers\Api\DocumentController; use App\Http\Controllers\Api\DocumentController;
use App\Http\Controllers\Api\TarifController; use App\Http\Controllers\Api\TarifController;
use App\Http\Controllers\Api\MultimediaCategoryController; 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('categories', [CategoryController::class, 'index']);
Route::get('tradings', [TradingsController::class, 'index']); Route::get('tradings', [TradingsController::class, 'index']);
Route::get('categories/{id}/tradings', [TradingsController::class, 'selectedTradings']); 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('media/categories', [MultimediaCategoryController::class, 'index']);
Route::get('medias/{category}', [MultimediaController::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']);

0
storage/app/settings.json Executable file → Normal file
View File

0
storage/app/setup.json Executable file → Normal file
View File