2018-08-11 05:09:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns the Service Options Model for an Order.
|
|
|
|
*/
|
|
|
|
namespace App\Traits;
|
|
|
|
|
2021-09-28 02:43:54 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2018-08-11 05:09:41 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
trait OrderServiceOptions
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
protected $order_attributes = [
|
|
|
|
'options.input'=>[
|
|
|
|
'request'=>'options.input',
|
|
|
|
'key'=>'column',
|
|
|
|
'validation'=>'required|string:10',
|
|
|
|
'validation_message'=>'It is a required field.',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $order_model = NULL;
|
|
|
|
*/
|
|
|
|
|
2021-09-28 02:43:54 +00:00
|
|
|
public function orderValidation(Request $request): ?Model
|
2018-08-11 05:09:41 +00:00
|
|
|
{
|
2021-09-28 02:43:54 +00:00
|
|
|
if ((! isset($this->order_attributes)) || (! isset($this->order_model)))
|
2018-08-11 05:09:41 +00:00
|
|
|
return NULL;
|
|
|
|
|
2021-09-28 04:55:03 +00:00
|
|
|
$request->validate(collect($this->order_attributes)->pluck('validation','request')->toArray());
|
2018-08-11 05:09:41 +00:00
|
|
|
|
|
|
|
$o = new $this->order_model;
|
|
|
|
|
|
|
|
$x = [];
|
|
|
|
foreach ($this->order_attributes as $k => $v)
|
|
|
|
$x[$v['key']] = $request->input($k);
|
|
|
|
|
|
|
|
$o->forceFill(array_undot($x));
|
|
|
|
|
|
|
|
// @todo Make this automatic
|
2021-07-09 01:39:27 +00:00
|
|
|
$o->site_id = config('SITE')->site_id;
|
2018-08-11 05:09:41 +00:00
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|