Implemented deletion and creation of people.
This commit is contained in:
@@ -6,6 +6,7 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
|
||||||
use App\Person;
|
use App\Person;
|
||||||
|
use App\MemberState;
|
||||||
|
|
||||||
|
|
||||||
class PeopleController extends Controller
|
class PeopleController extends Controller
|
||||||
@@ -28,22 +29,97 @@ class PeopleController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show the form for creating a new person
|
// Show the form for creating a new person
|
||||||
public function create() {}
|
public function create() {
|
||||||
|
$person = new Person();
|
||||||
|
return view('people.create', compact('person'));
|
||||||
|
}
|
||||||
|
|
||||||
// Store a new person in the database
|
// Store a new person in the database
|
||||||
public function store() {}
|
public function store() {
|
||||||
|
// Create a new Person model and fill it with data from the request
|
||||||
|
$person = new Person();
|
||||||
|
|
||||||
|
$person->fill(request([
|
||||||
|
'title',
|
||||||
|
'name_or_company',
|
||||||
|
'surname',
|
||||||
|
'street',
|
||||||
|
'postal_code',
|
||||||
|
'city',
|
||||||
|
'email',
|
||||||
|
'mobile',
|
||||||
|
'phone',
|
||||||
|
'date_of_birth'
|
||||||
|
]));
|
||||||
|
|
||||||
|
$person->save();
|
||||||
|
|
||||||
|
// If the member states data is non-empty, save a record to the database.
|
||||||
|
if (!is_null(request('joining_date')[0])) {
|
||||||
|
$memberState = new MemberState();
|
||||||
|
|
||||||
|
$memberState->joining_date = request('joining_date')[0];
|
||||||
|
$memberState->leaving_date = request('leaving_date')[0];
|
||||||
|
|
||||||
|
$person->memberStates()->save($memberState);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect to the people index page
|
||||||
|
return redirect('/people');
|
||||||
|
}
|
||||||
|
|
||||||
// Show the form for editing a existing person
|
// Show the form for editing a existing person
|
||||||
public function edit(Person $person) {
|
public function edit(Person $person)
|
||||||
|
{
|
||||||
return view('people.edit', compact('person'));
|
return view('people.edit', compact('person'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the edited data of an existing person in the database
|
// Store the edited data of an existing person in the database
|
||||||
public function update(Person $person) {}
|
public function update(Person $person)
|
||||||
|
{
|
||||||
|
// Create a new Person model and fill it with data from the request
|
||||||
|
$person->fill(request([
|
||||||
|
'title',
|
||||||
|
'name_or_company',
|
||||||
|
'surname',
|
||||||
|
'street',
|
||||||
|
'postal_code',
|
||||||
|
'city',
|
||||||
|
'email',
|
||||||
|
'mobile',
|
||||||
|
'phone',
|
||||||
|
'date_of_birth'
|
||||||
|
]));
|
||||||
|
|
||||||
|
$person->save();
|
||||||
|
|
||||||
|
// If the member states data is non-empty, save a record to the database.
|
||||||
|
if ($person->title != 'Firma') {
|
||||||
|
for ($i = 0; $i < sizeof(request('joining_date')); $i++) {
|
||||||
|
$memberState = MemberState::find(request('memberStateId')[$i]);
|
||||||
|
|
||||||
|
$memberState->joining_date = request('joining_date')[$i];
|
||||||
|
$memberState->leaving_date = request('leaving_date')[$i];
|
||||||
|
|
||||||
|
$memberState->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect to the people index page
|
||||||
|
return redirect('/people');
|
||||||
|
}
|
||||||
|
|
||||||
// Show the delete dialog for a given person
|
// Show the delete dialog for a given person
|
||||||
public function delete(Person $person) {}
|
public function delete(Person $person)
|
||||||
|
{
|
||||||
|
return view('people.delete', compact('person'));
|
||||||
|
}
|
||||||
|
|
||||||
// Actualla delete a person from the database
|
// Actually delete a person from the database
|
||||||
public function destroy(Person $person) {}
|
public function destroy(Person $person)
|
||||||
|
{
|
||||||
|
$person->delete();
|
||||||
|
|
||||||
|
return redirect('/people');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<ul>
|
<ul style='list-style-type: none; padding: 0'>
|
||||||
<li><a href='/people'>Personen</a><br /></li>
|
<li><a href='/people'>Personen</a></li>
|
||||||
<li><a href='/people'>Kassenbuch</a><br /></li>
|
<li><a href='/people'>Kassenbuch</a></li>
|
||||||
<li><a href='/people'>F / V</a><br /></li>
|
<li><a href='/people'>F / V</a></li>
|
||||||
<li><a href='/people'>Personen</a><br /></li>
|
<li><a href='/people'>Personen</a></li>
|
||||||
<li><a href='/people'>Personen</a><br /></li>
|
<li><a href='/people'>Personen</a></li>
|
||||||
<li><a href='/people'>Personen</a><br /></li>
|
<li><a href='/people'>Personen</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
@extends('layout.forms.person')
|
||||||
|
|
||||||
|
@section('title', 'Neue Person')
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
@extends('layout.master')
|
||||||
|
|
||||||
|
@section('title', 'Person löschen')
|
||||||
|
|
||||||
|
@section('subnav')
|
||||||
|
<a href='{{ url()->previous() }}'>Zurück</a>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<form action='/people/{{ $person->id }}' method='post'>
|
||||||
|
{{ method_field('delete') }}
|
||||||
|
{{ csrf_field() }}
|
||||||
|
@if ($person->isEven())
|
||||||
|
<p>Soll <b>{{ $person->fullName() }}</b> wirklich gelöscht werden?</p>
|
||||||
|
<button type="submit" id="submit">Ja</button>
|
||||||
|
@else
|
||||||
|
<p><b>{{ $person->fullName() }}</b> kann nicht gelöscht werden, da es noch
|
||||||
|
offene Forderungen oder Verbindlichkeiten gibt.</p>
|
||||||
|
@endif
|
||||||
|
</form>
|
||||||
|
@endsection
|
||||||
|
|
||||||
Reference in New Issue
Block a user