OcotberCMS PivotModel $attachOne Relation
I am trying to create
many-to-many relation with a file attachment pivot in
Here's my relation
public $belongsToMany = [ 'users' => [ User::class, 'key' => 'task_id', 'otherKey' => 'user_id', 'table' => 'tasks_users', 'pivot' => ['status'], 'pivotModel' => TaskUser::class ] ];
In my pivotModel
class TaskUser extends Pivot ... public $attachOne = [ 'file' => ['System\Models\File'] ];
pivot: form: tabs: fields: pivot[file]: label: Image type: fileupload mode: image span: left tab: Image
The form is rendered correctly, but when trying to upload the file, the error is thrown:
Upload error "A widget with class name 'relationUsersManagePivotFormPivotFile' has not been bound to the controller" on line 605 of D:\Projects\esport\modules\backend\classes\Controller.php
It seems it's kind of a lot of nesting which the relation manager is not able to handle. As well
File does not work with
differed binding when in used in pivot modal.
Relation manager with
differed bindingpivot data is not supported Ref: https://octobercms.com/docs/backend/relations#belongs-to-many-pivot
So maybe we can use an alternate way. if that is possible.
- In pivot table you can add new field
- Specify it in relation config =>
'pivot' => ['status', 'file']
And now from the field
pivot: form: fields: pivot[value]: label: Value type: text pivot[file]: label: Picture type: mediafinder
Now you can upload and select files or select existing files. they will be stored as
file pathso they can directly be accessed.
if any doubt please comment.
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?