将多个参数从函数传递到函数并访问输入-Laravel

$myCourseData['points'] = "1";                 
 $myCourseData['totalPoints'] = "2";

$this->update($myCourseData,$myCourseId);
我想将points&;totalPoints从函数传递到函数update(),并以$request->points;的身份访问points中的points。我如何才能这样做?仅points&;totalPoints从上述函数传递,update()函数输入中的其他参数从其他地方传递。

function update($request,$id){

 $validator = Validator::make(
            $request->all(),
            [
                'course_id'       => 'nullable|integer',  
                'exam_numbers'    => 'nullable|integer',
                'points'          => 'nullable|integer', 
                'subscription' => 'nullable|boolean',
                'totalPoints'=>'nullable|integer'
            ]
        );     

$points =  $request->points;
}          
    

    

解决方案

我认为您需要在Request类对象中添加点数和总点数,然后发送到更新函数。在这里,我试图只使用一个控制器来实现一些东西。

<?php
use IlluminateHttpRequest;
use AppHttpControllersController;


class DashboardController extends Controller
{
    public function abc(){
        $myCourseData = new Request(["points" => "1", "totalPoints" => "2"]);
        $myCourseId = 5;

        $this->update($myCourseData,$myCourseId);
    }

    public function update(Request $request, $id){
        $points =  $request->points;
        dd($points);
    }
}

相关文章