added tariffs api
This commit is contained in:
parent
6b20008590
commit
fba2bc7784
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\TarifRequest;
|
||||
use Backpack\CRUD\app\Http\Controllers\CrudController;
|
||||
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
|
||||
|
||||
/**
|
||||
* Class TarifCrudController
|
||||
* @package App\Http\Controllers\Admin
|
||||
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
|
||||
*/
|
||||
class TarifCrudController extends CrudController
|
||||
{
|
||||
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
|
||||
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
|
||||
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
|
||||
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
|
||||
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
|
||||
use \Backpack\CRUD\app\Http\Controllers\Operations\ReorderOperation;
|
||||
|
||||
/**
|
||||
* Configure the CrudPanel object. Apply settings to all operations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
CRUD::setModel(\App\Models\Tarif::class);
|
||||
CRUD::setRoute(config('backpack.base.route_prefix') . '/tarif');
|
||||
CRUD::setEntityNameStrings('tarif', 'tarifs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Define what happens when the List operation is loaded.
|
||||
*
|
||||
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
|
||||
* @return void
|
||||
*/
|
||||
protected function setupListOperation()
|
||||
{
|
||||
CRUD::column('type')->type('select_from_array')->options(['resident' => 'Для резидентов', 'non_resident' => 'Для не резидентов'])->allows_null(false);
|
||||
CRUD::column('title');
|
||||
CRUD::column('prices');
|
||||
|
||||
/**
|
||||
* Columns can be defined using the fluent syntax or array syntax:
|
||||
* - CRUD::column('price')->type('number');
|
||||
* - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Define what happens when the Create operation is loaded.
|
||||
*
|
||||
* @see https://backpackforlaravel.com/docs/crud-operation-create
|
||||
* @return void
|
||||
*/
|
||||
protected function setupCreateOperation()
|
||||
{
|
||||
CRUD::setValidation(TarifRequest::class);
|
||||
|
||||
CRUD::field('type')->type('select_from_array')->options(['resident' => 'Для резидентов', 'non_resident' => 'Для не резидентов'])->allows_null(false);
|
||||
CRUD::field('title');
|
||||
CRUD::field('prices')->type('repeatable')->fields([
|
||||
[
|
||||
'name' => 'price',
|
||||
'type' => 'text',
|
||||
'label' => 'Price',
|
||||
'wrapper' => ['class' => 'form-group col-md-12'],
|
||||
],
|
||||
])->new_item_label("Add price");
|
||||
|
||||
/**
|
||||
* Fields can be defined using the fluent syntax or array syntax:
|
||||
* - CRUD::field('price')->type('number');
|
||||
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Define what happens when the Update operation is loaded.
|
||||
*
|
||||
* @see https://backpackforlaravel.com/docs/crud-operation-update
|
||||
* @return void
|
||||
*/
|
||||
protected function setupUpdateOperation()
|
||||
{
|
||||
$this->setupCreateOperation();
|
||||
}
|
||||
|
||||
protected function setupReorderOperation()
|
||||
{
|
||||
// define which model attribute will be shown on draggable elements
|
||||
$this->crud->set('reorder.label', 'title');
|
||||
// define how deep the admin is allowed to nest the items
|
||||
// for infinite levels, set it to 0
|
||||
$this->crud->set('reorder.max_level', 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Models\Tarif;
|
||||
use App\Transformers\TarifTransformer;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TarifController extends ApiController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$type = $request->type ?? null;
|
||||
if($type){
|
||||
$tarifs = Tarif::where('type', $type)->orderBy('lft', 'desc')->get();
|
||||
}else{
|
||||
$tarifs = Tarif::orderBy('lft', 'desc')->get();
|
||||
}
|
||||
return $this->respondWithCollection($tarifs, new TarifTransformer($this->locale));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\News;
|
||||
use App\Http\Requests\StoreNewsRequest;
|
||||
use App\Http\Requests\UpdateNewsRequest;
|
||||
|
||||
class NewsController 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\StoreNewsRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreNewsRequest $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(News $news)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(News $news)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\UpdateNewsRequest $request
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateNewsRequest $request, News $news)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(News $news)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreTarifRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TarifRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// only allow updates if the user is logged in
|
||||
return backpack_auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
// 'name' => 'required|min:5|max:255'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation attributes that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation messages that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateTarifRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Backpack\CRUD\app\Models\Traits\SpatieTranslatable\HasTranslations;
|
||||
|
||||
|
||||
class Tarif extends Model
|
||||
{
|
||||
use \Backpack\CRUD\app\Models\Traits\CrudTrait;
|
||||
use HasFactory;
|
||||
use HasTranslations;
|
||||
|
||||
protected $guarded = [''];
|
||||
public $translatable = ['title', 'prices'];
|
||||
|
||||
protected $casts = [
|
||||
'prices' => 'json',
|
||||
];
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Tarif;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class TarifPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function viewAny(User $user)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Tarif $tarif
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function view(User $user, Tarif $tarif)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function create(User $user)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Tarif $tarif
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function update(User $user, Tarif $tarif)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Tarif $tarif
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function delete(User $user, Tarif $tarif)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Tarif $tarif
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function restore(User $user, Tarif $tarif)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Tarif $tarif
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function forceDelete(User $user, Tarif $tarif)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Transformers;
|
||||
|
||||
use App\Models\Tarif;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class TarifTransformer extends TransformerAbstract
|
||||
{
|
||||
private $locale;
|
||||
|
||||
public function __construct($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
public function transform(Tarif $tarif)
|
||||
{
|
||||
return [
|
||||
'id' => $tarif->id,
|
||||
'type' => $tarif->type,
|
||||
'title' => $tarif->getTranslations('title', [$this->locale]),
|
||||
'prices' => $tarif->getTranslations('prices', [$this->locale]),
|
||||
];
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -119,13 +119,13 @@ return [
|
|||
// change background color with bg-dark, bg-primary, bg-secondary, bg-danger, bg-warning, bg-success, bg-info, bg-blue, bg-light-blue, bg-indigo, bg-purple, bg-pink, bg-red, bg-orange, bg-yellow, bg-green, bg-teal, bg-cyan, bg-white
|
||||
|
||||
// Developer or company name. Shown in footer.
|
||||
'developer_name' => 'Cristian Tabacitu',
|
||||
'developer_name' => 'TPS',
|
||||
|
||||
// Developer website. Link in footer. Type false if you want to hide it.
|
||||
'developer_link' => 'http://tabacitu.ro',
|
||||
|
||||
// Show powered by Laravel Backpack in the footer? true/false
|
||||
'show_powered_by' => true,
|
||||
'show_powered_by' => false,
|
||||
|
||||
// -------
|
||||
// SCRIPTS
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class TarifFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateTarifsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('tarifs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('type');
|
||||
$table->text('title');
|
||||
$table->string('prices');
|
||||
$table->integer('parent_id')->default(0)->nullable();
|
||||
$table->integer('lft')->default(0);
|
||||
$table->integer('rgt')->default(0);
|
||||
$table->integer('depth')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('tarifs');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class TarifSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
<li class="nav-item"><a class="nav-link" href="{{ backpack_url('category') }}"><i class="nav-icon la la-question"></i> Categories</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="{{ backpack_url('trading') }}"><i class="nav-icon la la-question"></i> Tradings</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="{{ backpack_url('selected-trading') }}"><i class="nav-icon la la-question"></i> Selected tradings</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="{{ backpack_url('news') }}"><i class="nav-icon la la-question"></i> News</a></li>
|
||||
<li class='nav-item'><a class='nav-link' href='{{ backpack_url('document') }}'><i class='nav-icon la la-question'></i> Documents</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="{{ backpack_url('selected-trading') }}"><i class="nav-icon la la-question"></i> Selected tradings</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="{{ backpack_url('tarif') }}"><i class="nav-icon la la-question"></i> Tarifs</a></li>
|
||||
|
|
@ -10,6 +10,7 @@ use App\Http\Controllers\Api\NewsController;
|
|||
use App\Http\Controllers\Api\CategoryController;
|
||||
use App\Http\Controllers\Api\DocumentController;
|
||||
use App\Http\Controllers\Api\SelectedTradingController;
|
||||
use App\Http\Controllers\Api\TarifController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
@ -34,3 +35,4 @@ 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']);
|
||||
|
|
|
|||
|
|
@ -21,4 +21,6 @@ Route::group([
|
|||
Route::crud('news', 'NewsCrudController');
|
||||
Route::crud('document', 'DocumentCrudController');
|
||||
Route::crud('selected-trading', 'SelectedTradingCrudController');
|
||||
|
||||
Route::crud('tarif', 'TarifCrudController');
|
||||
}); // this should be the absolute last line of this file
|
||||
Loading…
Reference in New Issue