如何将控制器索引函数的参数传递给模型的函数? LARAVEL

How can I pass a parameter from the controller index function to the model's functions? LARAVEL

//----------------------------// //下面是控制器索引函数代码// //----------------------------//

public function index($from, $to,$id)
    {
         $data=Attendance::where('attendance_date','>=',$from)
         ->where('attendance_date','<=',$to)
         ->with('userAttendance')//--> **I need to pass the $id to this function in the model**
         ->with('admin')
        ->get()

//--------------------------------// //下面是模型代码// //--------------------------------//

class Attendance extends Model
{
    protected $table = "attendances";
    protected $fillable=[
        'attendance_date',
        'admin_id',
    ];
                                       //---> **i need the $id passed to here**
    public function userAttendance()
    {
       return $this->belongsToMany('App\User', 'user_attendances','attendance_id','user_id')
       ->withPivot(
        'present_absent',
        'excuse',
        'attendance_key_amount',
        'verified_date',
        'comment',
       );
    }
}

试试这个

控制器:

 public function index()
    {
        $id = 50;
        Product::getId(50);
    }

型号:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    public static function getId($id){
        dd($id);
    }
}