This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi, working on a simple plugin with some custom fields + fileupload. I want to save the uploaded image path to my DB. How can i get the file path?
namespace jacoweb\Referances\Models; use Model; use BackendAuth; use Backend\Classes\FormWidgetBase;
class Referances extends Model {
use \October\Rain\Database\Traits\Purgeable;
use \October\Rain\Database\Traits\Validation;
public $table = 'referances';
protected $fillable = ['title', 'description'];
protected $purgeable = ['assign'];
public $hasMany = ['Referances' => ['jacoweb\Referances\Models\Referances']];
public $rules = ['title' => 'required'];
public function beforeCreate()
{
$this->user_id = BackendAuth::getUser()->id;
}
public $attachOne = [
'image' => ['System\Models\File']
];
public function beforeSave() {
$this->Image = 2; // $this->Image is the field in the DB
}
}
Last updated
how can i show the dump? sorry i fix it.. but the field is blank.. thats why hmm
Last updated
public $attachOne = [ 'file' => ['System\Models\File'] ];
public function beforeSave()
{
dd($this->file->getPath());
}
trying this code shows error: Call to a function member getPath() of a non-object.
I tried using withDeferred() it's working in Update but not during the Create. Can anyone produce a working code for File Attachment with deferred binding for both CRUD?
related: https://github.com/rainlab/builder-plugin/issues/25
solved: We don't need to define the file in Builder, attaching is enough
Last updated
marc17493 said:
related: https://github.com/rainlab/builder-plugin/issues/25
solved: We don't need to define the file in Builder, attaching is enough
What do you mean by not defining the file in builder? Could you please explain this in more detail? Thanks
1-10 of 10