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 App\Person;
|
||||
use App\MemberState;
|
||||
|
||||
|
||||
class PeopleController extends Controller
|
||||
@@ -28,22 +29,97 @@ class PeopleController extends Controller
|
||||
}
|
||||
|
||||
// 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
|
||||
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
|
||||
public function edit(Person $person) {
|
||||
public function edit(Person $person)
|
||||
{
|
||||
return view('people.edit', compact('person'));
|
||||
}
|
||||
|
||||
// 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
|
||||
public function delete(Person $person) {}
|
||||
public function delete(Person $person)
|
||||
{
|
||||
return view('people.delete', compact('person'));
|
||||
}
|
||||
|
||||
// Actualla delete a person from the database
|
||||
public function destroy(Person $person) {}
|
||||
// Actually delete a person from the database
|
||||
public function destroy(Person $person)
|
||||
{
|
||||
$person->delete();
|
||||
|
||||
return redirect('/people');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user