This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

jacoweb
jacoweb

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

Shahiem
Shahiem

$image->getPath();

jacoweb
jacoweb

Hi! When i use the variable $image->getPath(); i get "Undefined variable: Image"

Firestarter
Firestarter

$this->image = 2;

public function beforeSave() { dd($this); }

Last updated

jacoweb
jacoweb

white page using the dd function.. dd is the same like var dump right?

Firestarter
jacoweb
jacoweb

how can i show the dump? sorry i fix it.. but the field is blank.. thats why hmm

Last updated

herzgarlan22551
herzgarlan22551

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?

daslicht
daslicht

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

Creatief Ingewikkeld
Creatief Ingewikkeld

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

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.