Hello I am new to OctoberCMS and I am having the following problem:
I am trying to create a model with some image attached to it but I don't get it to work. This is my code:
My Model:
class Tree extends Model {
public $table = 'myplugin_trees_trees';
public $attachOne = [
'avatar' => ['System\Models\File']
];
public $dates = ['cut_at', 'dries_from', 'dries_to'];
}
My migration file:
class CreateTreesTable extends Migration {
public function up() {
Schema::create('myplugin_trees_trees', function($table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name');
$table->longText('description');
});
}
public function down() {
Schema::dropIfExists('myplugin_trees_trees');
}
}
And finally my controller:
class Trees extends \Backend\Classes\Controller {
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController',
];
public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';
public function __construct() {
parent::__construct();
BackendMenu::setContext('MyPlugin.Trees', 'trees', 'trees');
}
public function index(){
$this->asExtension('ListController')->index();
}
public function create() {
$this->bodyClass = 'compact-container';
return $this->asExtension('FormController')->create();
}
}
In my fields.yaml I have the following code:
avatar:
label: Avatar
type: fileupload
mode: image
imageHeight: 260
imageWidth: 260
I can add add a tree to the database but the attached file will not show up in the database records (I tried to add a 'attachments' field to the trees table as said in the documentation but this didn't work either). I don't get any warnings or errors when submitting the form to the database.
What am I missing?
Last updated