Hi, Am trying to attach a specific image/file to a record using the $attachOne relation. From the controller, everything works fine, the image upload successfully using the field.yaml file, but i can't seem to get the file uploaded from the component. Here is a piece of my code.
Model file:
use Model;
use Form;
class School extends Model
{
use \October\Rain\Database\Traits\Validation;
/**
* @var string The database table used by the model.
*/
public $table = 'schools';
/**
* @var array Guarded fields
*/
protected $guarded = ['*'];
/**
* @var array Fillable fields
*/
protected $fillable = [
'school_name',
'curriculums',
'avatar',
];
/**
* @var array Relations
*/
public $attachOne = ['avatar' => ['System\Models\File']];
public $attachMany = [];
}
Component file:
/**
* Add a school to the list
*/
public function onCreateSch()
{
$school_data = [
"school_name" => post('school_name'),
"curriculums" => post('school_cur'),
"avatar" => post('school_logo'),
];
$school = SchModel::create($school_data);
}
default.htm file
<form data-request="onCreateSch">
<div class="form-group">
<input name="school_name" type="text" placeholder="{{ 'Enter school name'|_ }}" class="form-control" required="required" />
</div>
<div class="form-group">
<input name="school_cur" type="text" placeholder="{{ 'Enter school Curriculum'|_ }}" class="form-control" required="required" />
</div>
<div class="form-group">
<input name="school_logo" type="file" />
</div>
<div class="form-group">
<button type="submit" class="btn btn-info"><strong>{{ 'SUBMIT'|_ }}</strong></button>
</div>
</form>