ReynardtheFox
2 months ago

Pass Multiple Values to the same function within a Controller

Posted 2 months ago by ReynardtheFox

I would like to see if it is possible to pass multiple value to a public function within a Controller. I have the following in my Controller

public function paid($id)
    {
        $r = Roll::find($id);
        $rollid = Rollmapping::latest()->value('id');
        if ($r != null)
        {
            $r->status = "C";
            $r->paidrollid = $rollid;
            $r->save();
            Alert::Success('Member Paid', 'Member Paid Cash')->autoclose(1500);
            return redirect(action('[email protected]'));
        }
        return redirect(action('[email protected]'));
    }
    public function voucher($id)
    {
        $r = Roll::find($id);
        $rollid = Rollmapping::latest()->value('id');
        if ($r != null)
        {
            // Check if ActiveKids Balance is not less than 0
            if ($r->member->ActiveKids->sum('balance') >= 10)
            {
                // Update Roll Status
                $r->status = "V";
                $r->paidrollid = $rollid;
                $r->save();
                // Insert Record into ActiveKids Voucher
                $voucher = new ActiveKids();
                $voucher->member_id = $r->member_id;
                $voucher->voucher_number = 'Weekly Subs';
                $voucher->balance = -10;
                $voucher->date_received = Carbon::now()->toDateString();
                $voucher->save();
                
                Alert::Success("Paid", "Member paid from Voucher Balance")->autoclose(1500);
                return redirect(action('[email protected]'));
            }
            else
            {
                //Not Enough money in the account
                Alert::Error("Error", "Insufficient Active Kids Balance")->autoclose(1500);
                return redirect(action('[email protected]'));
            }
        }
        return redirect(action('[email protected]'));
    }
    public function notpaid($id)
    {
        $r = Roll::find($id);
        if ($r != null)
        {
            $r->status = "P";
            $r->save();
            return redirect(action('[email protected]'))->with ('success', 'Member Present');
        }
        return redirect(action('[email protected]'));
    }

These are triggered by the following in my Blade view

<a href="{{action('[email protected]', $r->id)}}" title="Paid" class="btn btn-success btn-round"><i class="material-icons">done</i></a>
<a href="{{action('[email protected]', $r->id)}}"  title="Voucher" class="btn btn-info btn-round"><i class ="material-icons">local_activity</i></a>
<a href="{{action('[email protected]', $r->id)}}" title="Not Paid" class="btn btn-danger btn-round"><i class="material-icons">close</i></a>

As you can see, depending on the Button I select depends on the function I call.

Ideally I would like the following in my View

<a href="{{action('[email protected]', $r->id, 'c')}}" title="Paid" class="btn btn-success btn-round"><i class="material-icons">done</i></a>
<a href="{{action('[email protected]', $r->id, 'v')}}"  title="Voucher" class="btn btn-info btn-round"><i class ="material-icons">local_activity</i></a>
<a href="{{action('[email protected]', $r->id, 'p')}}" title="Not Paid" class="btn btn-danger btn-round"><i class="material-icons">close</i></a>

And the following in my controller

Public Function paid ($id, $type)
    $r = Roll::find($id);
        $rollid = Rollmapping::latest()->value('id');

    if($type = 'c')
        Actions for current paid function
    elseif($type = 'v')
        Actions for current voucher function
    elseif($type = 'p')
        Actions for current present function
    endif

Hope someone can help

FYI this is my routes

Route::get('/roll/paid/{id}', '[email protected]')->middleware('auth');
Route::get('/roll/voucher/{id}', '[email protected]')->middleware('auth');
Route::get('/roll/notpaid/{id}', '[email protected]')->middleware('auth');

Please sign in or create an account to participate in this conversation.