added transports

pull/44/head
A1Gard 6 months ago
parent 585e0cfecc
commit 2a3379ffad

@ -0,0 +1,131 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\TransportSaveRequest;
use App\Models\Access;
use App\Models\Transport;
use Illuminate\Http\Request;
use App\Helper;
use function App\Helpers\hasCreateRoute;
class TransportController extends XController
{
// protected $_MODEL_ = Transport::class;
// protected $SAVE_REQUEST = TransportSaveRequest::class;
protected $cols = ['title','price','is_default','icon'];
protected $extra_cols = ['id'];
protected $searchable = ['title','description'];
protected $listView = 'admin.transports.transport-list';
protected $formView = 'admin.transports.transport-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(Transport::class, TransportSaveRequest::class);
}
/**
* @param $transport Transport
* @param $request TransportSaveRequest
* @return Transport
*/
public function save($transport, $request)
{
$transport->price = $request->price;
$transport->title = $request->title;
$transport->icon = $request->icon;
$transport->description = $request->description;
$transport->is_default = $request->has('is_default');
if ($request->has('is_default')){
Transport::where('is_default',1)->where('id','<>',$transport->id)->update([
'is_default' => 0,
]);
$transport->is_default = 1;
}
$transport->save();
return $transport;
}
/**
* 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(Transport $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;
/**restore*/
case 'restore':
$msg = __(':COUNT items restored successfully', ['COUNT' => count($ids)]);
foreach ($ids as $id) {
$this->_MODEL_::withTrashed()->find($id)->restore();
}
break;
/*restore**/
default:
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
}
return $this->do_bulk($msg, $action, $ids);
}
public function destroy(Transport $item)
{
return parent::delete($item);
}
public function update(Request $request, Transport $item)
{
return $this->bringUp($request, $item);
}
/**restore*/
public function restore($item)
{
return parent::restoreing(Transport::withTrashed()->where('id', $item)->first());
}
/*restore**/
}

@ -0,0 +1,31 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class TransportSaveRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'title' => ['required','string','min:4'],
'price' => ['required','integer'],
'description' => ['nullable','string'],
'icon' => ['nullable','string'],
];
}
}

@ -4,8 +4,11 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Translatable\HasTranslations;
class Transport extends Model
{
use HasFactory;
use HasFactory,SoftDeletes,HasTranslations;
public $translatable = ['title', 'description'];
}

@ -13,11 +13,12 @@ return new class extends Migration
{
Schema::create('transports', function (Blueprint $table) {
$table->id();
$table->string('title',250);
$table->text('title');
$table->text('description')->nullable()->default(null);
$table->unsignedInteger('sort')->default(0);
$table->boolean('is_default')->default(0);
$table->unsignedInteger('price')->default(0);
$table->string('icon')->nullable();
$table->softDeletes();
$table->timestamps();
});

@ -32,7 +32,7 @@
</label>
<currency-input xname="price" xid="price" @error('price')
:err="true" @enderror :xvalue="{{old('price',$item->price??null)}}"></currency-input>
:err="true" @enderror xtitle="{{__('Base price')}}" :xvalue="{{old('price',$item->price??null)}}"></currency-input>
</div>
</div>
<div class="col-lg-6 mt-3">

@ -198,8 +198,20 @@
@case($col == 'expire')
{{$item->expire->ldate("Y-m-d")}}
@break
@case($col == 'icon')
<i class="{{$item->$col}}"></i>
@break
@case($col == 'is_default')
@if($item->$col == 1)
<i class="ri-check-line"></i>
@endif
@break
@default
{{$item->$col}}
@if(gettype($item->$col) == 'integer')
{{number_format($item->$col)}}
@else
{{$item->$col}}
@endif
@endswitch
</td>
@endif

@ -0,0 +1,94 @@
@extends('admin.templates.panel-form-template')
@section('title')
@if(isset($item))
{{__("Edit transport")}} [{{$item->title}}]
@else
{{__("Add new transport")}}
@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 class="item-list mb-3">
<h3 class="p-3">
<i class="ri-remixicon-line"></i>
{{__("Icon")}}
</h3>
<div class="p-1 text-center pb-4">
<remix-icon-picker xname="icon" xvalue="{{old('icon',$item->icon??null)}}"></remix-icon-picker>
</div>
</div>
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form ">
<h1>
@if(isset($item))
{{__("Edit transport")}} [{{$item->title}}]
@else
{{__("Add new transport")}}
@endif
</h1>
<div class="row">
<div class="col-md-6 mt-3">
<div class="form-group">
<label for="title">
{{__('Title')}}
</label>
<input name="title" id="title" type="text" class="form-control @error('title') is-invalid @enderror" placeholder="{{__('Title')}}" value="{{old('title',$item->title??null)}}" />
</div>
</div>
<div class="col-md-6 mt-3">
<div class="form-group">
<label for="price">
{{__('Price')}}
</label>
<currency-input xname="price" xid="price" @error('price')
:err="true" @enderror :xvalue="{{old('price',$item->price??null)}}"></currency-input>
</div>
</div>
<div class="col-md-12 mt-3">
<div class="form-group">
<label for="description">
{{__('Description')}}
</label>
<textarea id="description" name="description" rows="4" class="form-control @error('description') is-invalid @enderror" placeholder="{{__('Description')}}" >{{old('description',$item->description??null)}}</textarea>
</div>
</div>
<div class="col-md-12 mt-3 mr-5">
<div class="form-group">
<div class="form-check form-switch">
<input value="1" class="form-check-input @error('is_default') is-invalid @enderror" name="is_default" @if( isset($item) && $item->is_default) checked @endif type="checkbox" id="is_default">
<label class="form-check-label" for="is_default"> {{__('Is default')}}</label>
</div>
</div>
</div>
<div class="col-md-12">
<label> &nbsp; </label>
<input name="" type="submit" class="btn btn-primary mt-2" value="{{__('Save')}}" />
</div>
</div>
</div>
</div>
</div>
@endsection

@ -0,0 +1,15 @@
@extends('admin.templates.panel-list-template')
@section('list-title')
<i class="ri-user-3-line"></i>
{{__("Transports list")}}
@endsection
@section('title')
{{__("Transports list")}} -
@endsection
@section('filter')
{{-- Other filters --}}
@endsection
@section('bulk')
{{-- <option value="-"> - </option> --}}
@endsection

@ -58,7 +58,7 @@
</a>
</li>
<li>
<a>
<a href="{{ route('admin.transport.index') }}">
<i class="ri-truck-fill"></i>
{{__('Transports')}}
</a>

@ -64,6 +64,20 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group(
Route::post('bulk', [\App\Http\Controllers\Admin\DiscountController::class, "bulk"])->name('bulk');
Route::get('trashed', [\App\Http\Controllers\Admin\DiscountController::class, "trashed"])->name('trashed');
});
Route::prefix('transports')->name('transport.')->group(
function () {
Route::get('', [\App\Http\Controllers\Admin\TransportController::class, 'index'])->name('index');
Route::get('create', [\App\Http\Controllers\Admin\TransportController::class, 'create'])->name('create');
Route::post('store', [\App\Http\Controllers\Admin\TransportController::class, 'store'])->name('store');
Route::get('edit/{item}', [\App\Http\Controllers\Admin\TransportController::class, 'edit'])->name('edit');
Route::post('update/{item}', [\App\Http\Controllers\Admin\TransportController::class, 'update'])->name('update');
Route::get('delete/{item}', [\App\Http\Controllers\Admin\TransportController::class, 'destroy'])->name('destroy');
Route::get('restore/{item}', [\App\Http\Controllers\Admin\TransportController::class, 'restore'])->name('restore');
Route::post('bulk', [\App\Http\Controllers\Admin\TransportController::class, "bulk"])->name('bulk');
Route::get('trashed', [\App\Http\Controllers\Admin\TransportController::class, "trashed"])->name('trashed');
});
Route::prefix('categories')->name('category.')->group(
function () {
Route::get('', [\App\Http\Controllers\Admin\CategoryController::class, 'index'])->name('index');

Loading…
Cancel
Save