mirror of https://github.com/4xmen/xshop.git
added transports
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'],
|
||||
];
|
||||
}
|
||||
}
|
@ -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> </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
|
Loading…
Reference in New Issue