В качестве основного ответа используется тип CIFSPacket, который не является (или больше не доступен) на C #, я написал правильные методы:
static byte[] getBytes(object str)
{
int size = Marshal.SizeOf(str);
byte[] arr = new byte[size];
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(str, ptr, true);
Marshal.Copy(ptr, arr, 0, size);
Marshal.FreeHGlobal(ptr);
return arr;
}
static T fromBytes<T>(byte[] arr)
{
T str = default(T);
int size = Marshal.SizeOf(str);
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.Copy(arr, 0, ptr, size);
str = (T)Marshal.PtrToStructure(ptr, str.GetType());
Marshal.FreeHGlobal(ptr);
return str;
}
Протестировано, они работают.
основываясь на ответе vivek_23 и после серфинга в интернете, я нашел решение этой проблемы.
мы не можем добавить дополнительные поля в метод правил, нам нужно добавить их в конструктор.
вот мой окончательный код.
<?php
namespace App\Containers\Package\UI\API\Requests;
use App\Ship\Parents\Requests\Request;
use Auth;
/**
* Class CreatePackageServiceRequest.
*/
class CreatePackageServiceRequest extends Request
{
/**
* The assigned Transporter for this Request
*
* @var string
*/
// protected $transporter = \App\Ship\Transporters\DataTransporter::class;
/**
* Define which Roles and/or Permissions has access to this request.
*
* @var array
*/
protected $access = [
'permissions' => '',
'roles' => '',
];
/**
* Id's that needs decoding before applying the validation rules.
*
* @var array
*/
protected $decode = [
// 'id',
];
/**
* Defining the URL parameters (e.g, `/user/{id}`) allows applying
* validation rules on them and allows accessing them like request data.
*
* @var array
*/
protected $urlParameters = [
// 'id',
];
public function __construct(\Illuminate\Http\Request $request)
{
$request->request->add([
'user_id' => Auth::user()->id,
'vendor_id' => Auth::user()->ownedVendor->id
]);
}
/**
* @return array
*/
public function rules()
{
// $this->merge([
// 'user_id' => Auth::user()->id,
// 'vendor_id' => Auth::user()->ownedVendor->id
// ]);
// dd($this->all());
return [
'name' => 'required|max:255',
'has_limited_number_of_event' => 'required',
'min_length' => 'required|numeric',
'max_length' => 'required|numeric|min:'.($this->get('min_length') + 1),
'max_booking' => 'required',
'message_on_booking_full' => 'required',
'allow_choose_host' => 'required',
'allow_skip' => 'required',
'host_name' => 'required',
'allow_extra_booking' => 'required',
'message_no_host_available' => 'required',
'has_photobooth_operator' => 'required',
'require_photobooth_background' => 'required',
'require_customization' => 'required',
'customization_title' => 'required',
'customization_label' => 'required',
'user_id' => 'required',
'vendor_id' => 'required',
// '{user-input}' => 'required|max:255',
];
}
/**
* @return bool
*/
public function authorize()
{
return $this->check([
'hasAccess',
]);
}
}
спасибо.