Commit 14681d2d2daf27aaaad4618adcda3911e1b99fc3

Authored by Андрей Ларионов
1 parent 415bebd6cd

Работодатели кабинет - редактирование флота

Showing 5 changed files with 181 additions and 5 deletions Side-by-side Diff

app/Http/Controllers/EmployerController.php
... ... @@ -131,6 +131,26 @@ class EmployerController extends Controller
131 131 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен');
132 132 }
133 133  
  134 + public function edit_flot(Flot $Flot, Employer $Employer) {
  135 + return view('employers.edit-flot', compact('Flot', 'Employer'));
  136 + }
  137 +
  138 + public function update_flot(FlotRequest $request, Flot $Flot) {
  139 + $params = $request->all();
  140 +
  141 + if ($request->has('image')) {
  142 + if (!empty($flot->image)) {
  143 + Storage::delete($flot->image);
  144 + }
  145 + $params['image'] = $request->file('image')->store("flot", 'public');
  146 + } else {
  147 + if (!empty($flot->image)) $params['image'] = $flot->image;
  148 + }
  149 +
  150 + $Flot->update($params);
  151 + return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен');
  152 + }
  153 +
134 154 public function delete_flot(Flot $Flot) {
135 155 $data_flots = Flot::query()->where('employer_id', $Flot->employer_id)->get();
136 156  
app/Http/Requests/FlotRequest.php
... ... @@ -26,10 +26,10 @@ class FlotRequest extends FormRequest
26 26 return [
27 27 'name' => 'required|min:3|max:255',
28 28 'text' => 'required|min:5',
29   - 'image' => [
30   - 'mimes:jpeg,jpg,png',
31   - 'max:20000'
32   - ],
  29 + //'image' => [
  30 + // 'mimes:jpeg,jpg,png',
  31 + // 'max:20000'
  32 + //],
33 33 'region' => 'required|min:3|max:255',
34 34 'power' => 'required|min:3|max:255'
35 35 ];
resources/views/employers/edit-flot.blade.php
... ... @@ -0,0 +1,147 @@
  1 +@extends('layout.frontend', ['title' => 'Редактирование флота - РекаМоре'])
  2 +
  3 +@section('scripts')
  4 + <script src="https://cdn.ckeditor.com/ckeditor5/23.0.0/classic/ckeditor.js"></script>
  5 + <script>
  6 + ClassicEditor
  7 + .create( document.querySelector( '#txtarea' ) )
  8 + .catch( error => {
  9 + console.error( error );
  10 + } );
  11 + </script>
  12 +@endsection
  13 +@section('content')
  14 + <section class="cabinet">
  15 + <div class="container">
  16 + <ul class="breadcrumbs cabinet__breadcrumbs">
  17 + <li><a href="{{ route('index') }}">Главная</a></li>
  18 + <li><b>Личный кабинет</b></li>
  19 + </ul>
  20 + <div class="cabinet__wrapper">
  21 + <div class="cabinet__side">
  22 + <div class="cabinet__side-toper">
  23 + @include('employers.emblema')
  24 + </div>
  25 +
  26 + @include('employers.menu', ['item' => 12])
  27 +
  28 + </div>
  29 + <div class="cabinet__body">
  30 + @include('messages_error')
  31 +
  32 + <div class="cabinet__body-item">
  33 + <div class="cabinet__descr">
  34 + <h2 class="title cabinet__title">Редактирование флота</h2>
  35 + </div>
  36 +
  37 + <form action="{{ route('employer.update_flot_save', ['Flot' => $Flot->id]) }}" enctype="multipart/form-data" method="POST" class="cabinet__add">
  38 + @csrf
  39 + <label class="cabinet__add-pic" style="vertical-align: top">
  40 + <input type="file" name="image" id="image">
  41 + @error('image')
  42 + <span class="text-xs text-red-600">
  43 + {{ $message }}
  44 + </span>
  45 + @enderror
  46 + <input type="hidden" name="employer_id" id="employer_id" value="{{ $Employer->id }}"/>
  47 + <svg>
  48 + <use xlink:href="{{ asset('images/sprite.svg#pic') }}"></use>
  49 + </svg>
  50 + <span>
  51 + <svg>
  52 + <use xlink:href="{{ asset('images/sprite.svg#plus') }}"></use>
  53 + </svg>
  54 + Загрузить фото
  55 + </span>
  56 + </label>
  57 +
  58 + <div class="cabinet__add-body">
  59 + <div class="form-group">
  60 + <label class="form-group__label">Название</label>
  61 + <div class="form-group__item">
  62 + <input type="text" name="name" id="flot_name" class="input" value="{{ old('name') ?? $Flot->name ?? '' }}" placeholder="Корабль №000001" required>
  63 + @error('name')
  64 + <span class="text-xs text-red-600">
  65 + {{ $message }}
  66 + </span>
  67 + @enderror
  68 + </div>
  69 + </div>
  70 + <div class="form-group" style="display:none">
  71 + <label class="form-group__label">Описание</label>
  72 + <div class="form-group__item">
  73 + <input type="text" name="text" id="flot_text" class="input" placeholder="Это судно находится..." value="{{ old('text') ?? $Flot->text ?? '' }}">
  74 + @error('text')
  75 + <span class="text-xs text-red-600">
  76 + {{ $message }}
  77 + </span>
  78 + @enderror
  79 + </div>
  80 + </div>
  81 + <div class="form-group" style="display:none">
  82 + <label class="form-group__label">Регион</label>
  83 + <div class="form-group__item">
  84 + <input type="text" name="region" id="region" class="input" placeholder="Мурманск" value="{{ old('region') ?? $Flot->region ?? '' }}">
  85 + @error('region')
  86 + <span class="text-xs text-red-600">
  87 + {{ $message }}
  88 + </span>
  89 + @enderror
  90 + </div>
  91 + </div>
  92 + <div class="form-group" style="display:none">
  93 + <label class="form-group__label">Мощность</label>
  94 + <div class="form-group__item">
  95 + <input type="text" name="power" id="flot_power" class="input" placeholder="Dw 40000 9000Kw" value="{{ old('power') ?? $Flot->power ?? '' }}">
  96 + @error('power')
  97 + <span class="text-xs text-red-600">
  98 + {{ $message }}
  99 + </span>
  100 + @enderror
  101 + </div>
  102 + </div>
  103 + <div class="form-group">
  104 + <label class="form-group__label">DWT</label>
  105 + <div class="form-group__item">
  106 + <input type="text" name="DWT" id="flot_DWT" class="input" placeholder="4000 т" value="{{ old('DWT') ?? $Flot->DWT ?? '' }}">
  107 + @error('DWT')
  108 + <span class="text-xs text-red-600">
  109 + {{ $message }}
  110 + </span>
  111 + @enderror
  112 + </div>
  113 + </div>
  114 + <div class="form-group">
  115 + <label class="form-group__label">Мощность ГД (кВт)</label>
  116 + <div class="form-group__item">
  117 + <input type="text" name="POWER_GD" id="flot_POWER_GD" class="input" placeholder="14000 кВт" value="{{ old('POWER_GD') ?? $Flot->POWER_GD ?? '' }}">
  118 + @error('POWER_GD')
  119 + <span class="text-xs text-red-600">
  120 + {{ $message }}
  121 + </span>
  122 + @enderror
  123 + </div>
  124 + </div>
  125 + <div class="form-group" style="">
  126 + <label class="form-group__label">IMO</label>
  127 + <div class="form-group__item">
  128 + <input type="text" name="IMO" id="flot_IMO" class="input" placeholder="8814275" value="{{ old('IMO') ?? $Flot->IMO ?? '' }}">
  129 + @error('IMO')
  130 + <span class="text-xs text-red-600">
  131 + {{ $message }}
  132 + </span>
  133 + @enderror
  134 + </div>
  135 + </div>
  136 + <button type="submit" class="button" id="ajax_flot-" name="ajax_flot-">Сохранить флот</button>
  137 + </div>
  138 + </form>
  139 + </div>
  140 + </div>
  141 + </div>
  142 + </div>
  143 +
  144 + </section>
  145 + </div>
  146 + <!-- END TOP WRAPPER -->
  147 +@endsection
resources/views/employers/fly-flot.blade.php
... ... @@ -133,7 +133,7 @@
133 133 @enderror
134 134 </div>
135 135 </div>
136   - <button type="submit" class="button" id="ajax_flot" name="ajax_flot">Добавить флот</button>
  136 + <button type="submit" class="button" id="ajax_flot_" name="ajax_flot_">Добавить флот</button>
137 137 </div>
138 138  
139 139 </form>
... ... @@ -143,11 +143,18 @@
143 143 @if ($Employer[0]->flots->count())
144 144 @foreach ($Employer[0]->flots as $it)
145 145 <div class="cabinet__fleet-item main__employer-page-one-item">
  146 + <div style="margin-bottom: -10px">
146 147 <a class="del die_black" href="{{ route('employer.delete_flot', ['Flot' => $it->id]) }}">
147 148 <svg>
148 149 <use xlink:href="{{ asset('images/sprite.svg#del') }}"></use>
149 150 </svg>
150 151 </a>
  152 + <a href="{{ route('employer.edit_flot', ['Flot' => $it->id, 'Employer' => $Employer[0]->id]) }}" class="del die_black" style="margin-left: 40px">
  153 + <svg>
  154 + <use xlink:href="{{ asset('images/sprite.svg#pencil') }}"></use>
  155 + </svg>
  156 + </a>
  157 + </div>
151 158 @if (!empty($it->image))
152 159 <img src="{{ asset(Storage::url($it->image)) }}" alt="{{ $it->name }}">
153 160 @else
... ... @@ -557,6 +557,8 @@ Route::group([
557 557 Route::post('cabinet/{Employer}', [EmployerController::class, 'cabinet_save'])->name('cabinet_save');
558 558 Route::post('flot_add_ajax', [EmployerController::class, 'save_add_flot'])->name('save_add_flot');
559 559 Route::get('flot_delete_ajax/{Flot}', [EmployerController::class, 'delete_flot'])->name('delete_flot');
  560 + Route::get('cabinet/flot_edit/{Flot}/{Employer}', [EmployerController::class, 'edit_flot'])->name('edit_flot');
  561 + Route::post('cabinet/flot_edit/{Flot}', [EmployerController::class, 'update_flot'])->name('update_flot_save');
560 562 Route::get('cabinet/flot', [EmployerController::class, 'slider_flot'])->name('slider_flot');
561 563  
562 564 // 2 страница - Добавление вакансий