This commit is contained in:
philipp lang 2021-07-15 20:56:53 +02:00
parent c767ff1198
commit 7abefa52e6
4 changed files with 12 additions and 8 deletions

View File

@ -3,23 +3,24 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Activity extends Model
{
public $fillable = ['name', 'nami_id'];
public $timestamps = false;
public $casts = [
'nami_id' => 'integer'
];
public function subactivities() {
public function subactivities(): BelongsToMany {
return $this->belongsToMany(Subactivity::class);
}
public static function nami($id) {
public static function nami(int $id): ?self {
return static::firstWhere('nami_id', $id);
}
}

View File

@ -15,11 +15,12 @@ use App\Group;
use App\Payment\Subscription;
use App\Http\Views\MemberView;
use App\Member\DeleteJob;
use Inertia\Response;
class MemberController extends Controller
{
public function index(Request $request) {
public function index(Request $request): Response {
session()->put('menu', 'member');
session()->put('title', 'Mitglieder');
@ -32,7 +33,7 @@ class MemberController extends Controller
return \Inertia::render('member/Index', $payload);
}
public function create() {
public function create(): Response {
session()->put('menu', 'member');
session()->put('title', 'Mitglied erstellen');
@ -40,7 +41,7 @@ class MemberController extends Controller
return \Inertia::render('member/Form', [
'activities' => $activities->pluck('name', 'id'),
'subactivities' => $activities->map(function($activity) {
'subactivities' => $activities->map(function(Activity $activity) {
return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
})->pluck('subactivities', 'id'),
'billKinds' => BillKind::get()->pluck('name', 'id'),

View File

@ -8,6 +8,7 @@ use App\Group;
use Illuminate\Support\Str;
use App\Activity;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
class MemberRequest extends FormRequest
{
@ -57,8 +58,8 @@ class MemberRequest extends FormRequest
];
}
public function persistCreate() {
$this->merge(['group_id' => Group::where('nami_id', auth()->user()->getNamiGroupId())->firstOrFail()->id]);
public function persistCreate(): void {
$this->merge(['group_id' => Group::where('nami_id', Auth::user()->getNamiGroupId())->firstOrFail()->id]);
$member = Member::create($this->input());
if($this->input('has_nami')) {
CreateJob::dispatch($member, auth()->user());

View File

@ -24,4 +24,5 @@ class PaymentResource extends JsonResource
'is_accepted' => $this->status->isAccepted(),
];
}
}