sprzęt - dodawanie, wyświetlanie i edycja

This commit is contained in:
Krzysztof Strzelecki 2019-12-06 02:00:06 +01:00
parent aab5c69c84
commit e23f514556
9 changed files with 267 additions and 4 deletions

View File

@ -0,0 +1,88 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\equipment;
use DB;
class EquipmentController extends Controller
{
public function create(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$equipment = DB::table('equipment')->where("fireStationID", '=', auth()->user()->fireStationID)
->get();
return view("equipment", ["equipment" => $equipment]);
} else{
return view('equipment');
}
}
public function addForm(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
return view('equipmentAdd');
} else return view("login");
}
public function editForm($id)
{
if(auth()->user() != null && auth()->user()->fireStationID != null )
{
$equipment = DB::table('equipment')->where("id", $id)->first();
return view('equipmentEdit', ["equipment" => $equipment]);
}
else
return view("login");
}
public function store(){
$this->validate(request(), [
'name' => 'required',
'amount' => 'required|numeric',
],
[
'required' => ':attribute jest wymagany(a).',
'numeric' => ':attribute powinna zawierać tylko cyfry.',
]);
$request = request();
$equipment = equipment::create([
'fireStationID' => auth()->user()->fireStationID,
'name' => $request-> name,
'amount' => $request-> amount,
'parameter' => $request-> parameter,
]);
return redirect()->to('/sprzet');
}
public function update(){
$this->validate(request(), [
'name' => 'required',
'amount' => 'required|numeric',
],
[
'required' => ':attribute jest wymagany(a).',
'numeric' => ':attribute powinna zawierać tylko cyfry.'
]);
$request = request();
$equipment = equipment::find( $request->equipmentID);
$equipment-> name = $request-> name;
$equipment-> amount = $request-> amount;
$equipment-> parameter = $request-> parameter;
$equipment->save();
return EquipmentController::create();
}
}

16
app/equipment.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class equipment extends Model
{
protected $primaryKey = 'id';
protected $table = 'equipment';
protected $fillable = [
'fireStationID','name', 'amount', 'parameter',
];
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEquipmentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('equipment', function (Blueprint $table) {
$table->increments('id');
$table->integer('fireStationID');
$table->string('name', 45);
$table->integer('amount');
$table->string('parameter', 45)->nullable();
$table->boolean('deleted')->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('equipment');
}
}

View File

@ -161,6 +161,7 @@ return [
'unitName' => 'nazwa jednostki',
'longitude' => 'długość geograficzna',
'latitude' => 'szerokość geograficzna',
'amount' => 'ilość'
],

View File

@ -3,14 +3,16 @@
@section('left-menu')
@parent
<ul>
<li>Dodaj<img src="img/left_menu_icon/add.png"></li>
<li>Edytuj<img src="img/left_menu_icon/edit.png"></li>
<li>Usuń<img src="img/left_menu_icon/delete.png"></li>
<a href="/sprzet"><li>Sprzęt<img src="img/left_menu_icon/more.png"></li></a>
{{-- <li>Edytuj<img src="img/left_menu_icon/edit.png"></li> --}}
{{-- <li>Usuń<img src="img/left_menu_icon/delete.png"></li> --}}
</ul>
@stop
@section('center-area')
@parent
Strona w budowie
<p>Zawarte będą tutaj informację o umundurowaniu oraz sprzęcie jaki jest na wyposarzeniu strażnicy oraz informacje gdzie umundurowanie się znajduje(druhowie mundury koszarowe oraz galowe mają w w domach, informacja ta pozwoli na sprawdzenie np jakie braki w umundurowaniu)</p>
<p>Zawarte będą tutaj informacje o umundurowaniu oraz sprzęcie jaki jest na wyposażeniu strażnicy oraz informacje gdzie umundurowanie się znajduje(druhowie mundury koszarowe oraz galowe mają w w domach, informacja ta pozwoli na sprawdzenie np jakie braki w umundurowaniu).</p>
@stop

View File

@ -0,0 +1,40 @@
@extends('layout.app')
@section('left-menu')
@parent
<ul>
<a href="sprzet/add"><li>Dodaj<img src="../img/left_menu_icon/add.png"></li></a>
<li>Edytuj<img src="../img/left_menu_icon/edit.png"></li>
<li>Usuń<img src="../img/left_menu_icon/delete.png"></li>
</ul>
@stop
@section('center-area')
@parent
@if( auth()->check())
@if( auth()->user()->fireStationID == NULL)
Jednostka nie istnieje
@else
<table class='firefighterViewTable'>
<tr class='table-header'>
<td>Nazwa</td>
<td>Ilość</td>
<td>Param. charakterystyczny</td>
@foreach($equipment as $item)
<tr>
<td id="name{{ $item->id }}">{{ $item->name }}</td>
<td id="amount{{ $item->id }}">{{ $item->amount }}</td>
<td id="parameter{{ $item->id }}">{{ $item->parameter }}</td>
<td><a href="{{ URL::asset('sprzet/edit/'.$item->id) }}"><input type="button" onclick="" value="Edytuj"> </a></td>
</tr>
@endforeach
</table>
@endif
@else
Brak autoryzacji
@endif
@stop

View File

@ -0,0 +1,36 @@
@extends('layout.app')
@section('left-menu')
@parent
<ul>
<a href="/sprzet/add"><li>Dodaj<img src="/./img/left_menu_icon/add.png"></li></a>
<li>Edytuj<img src="/./img/left_menu_icon/edit.png"></li>
<li>Usuń<img src="/./img/left_menu_icon/delete.png"></li>
</ul>
@stop
@section('center-area')
@parent
<form method="POST" action="/sprzet">
{{ csrf_field() }}
<div class="form-group">
<label for="name">Nazwa:</label>
<input type="text" class="form-control" id="name" name="name" value="{{ old('name') }} ">
</div>
<div class="form-group">
<label for="amount">Ilość:</label>
<input type="text" class="form-control" id="amount" name="amount" value="{{ old('amount') }}">
</div>
<div class="form-group">
<label for="parameter">Parametr charakterystyczny:</label>
<input type="text" class="form-control" id="parameter" name="parameter" value="{{ old('parameter') }}">
</div>
<div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zatwierdź</button>
</div>
@include('inc.formerrors')
</form>
@stop

View File

@ -0,0 +1,38 @@
@extends('layout.app')
@section('left-menu')
@parent
<ul>
<a href="/sprzet/add"><li>Dodaj<img src="/./img/left_menu_icon/add.png"></li></a>
<li>Edytuj<img src="/./img/left_menu_icon/edit.png"></li>
<li>Usuń<img src="/./img/left_menu_icon/delete.png"></li>
</ul>
@stop
@section('center-area')
@parent
<form method="POST" action="/sprzet/edit">
{{ csrf_field() }}
<input type="hidden" class="form-control" name="equipmentID" value="{{ $equipment->id }}">
<div class="form-group">
<label for="name">Nazwa:</label>
<input type="text" class="form-control" id="name" name="name" value="{{ $equipment->name }} ">
</div>
<div class="form-group">
<label for="amount">Ilość:</label>
<input type="text" class="form-control" id="amount" name="amount" value="{{ $equipment->amount }}">
</div>
<div class="form-group">
<label for="parameter">Parametr charakterystyczny:</label>
<input type="text" class="form-control" id="parameter" name="parameter" value="{{ $equipment->parameter }}">
</div>
<div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zatwierdź</button>
</div>
@include('inc.formerrors')
</form>
@stop

View File

@ -63,6 +63,12 @@ Route::get('/pojazdy/edit/{id}', 'VehiclesController@editForm');
Route::post('/pojazdy/edit', 'VehiclesController@update');
Route::get('/sprzet', 'EquipmentController@create');
Route::get('/sprzet/add', 'EquipmentController@addForm');
Route::post('/sprzet', 'EquipmentController@store');
Route::get('/sprzet/edit/{id}', 'EquipmentController@editForm');
Route::post('/sprzet/edit', 'EquipmentController@update');
Route::get('register/verify/{confirmationCode}', [
'as' => 'confirmation_path',
'uses' => 'RegistrationController@confirm'