I'm having trouble figuring out how to call a class function, in this case File->saveFile()
through the parent class Article
class Article extends Model {
public $table = 'pl_gen_article';
public function background_image () {
return $this->morphOne('App\Ubercms\File', 'fileable');
}
}
class File extends Model {
public $table = 'ubercms_file';
public function saveFile (UploadedFile $file) {}
}
$articleId = \Route::input('id');
$article = Article::findOrFail($articleId);
$file = $request->file('image');
// ----------------------
// Attempts
// 1.
$article->background_image->saveFile($file)
// 2.
$image = new $article->background_image();
$image->saveFile($file);
How do I create a File
model instance from Article
model?