Helllo, Hello
I am trying to upload a file at Laravel. However when I am at the controller, whatever method that tries to contact the object complains that it is not such an object and it cannot get its properties.
I have three fields, category, title and content, and then the file itself. I have searched here and there is some complicated code for uploading multiple files and then what resembles mine, yet without approved answers.
I also dont understand how the process is, I am just imagining it. I mean, one method can actually place the file in a folder in the server but I also need its path to be stored in the table of the database. I dont know that that actually happens, I read the documentation in Laravel docs and this is below what I have.
$category = Input::get('category');
$title = Input::get('title');
$content = Input::get('content');
$thefile = Input::file('fichero');
$filename = Input::file($thefile)->getClientOriginalName();
$destinationPath = "etc etc://../laravel/cosas";
Input::file('fichero')->move($destinationPath, $fileName);
$path = Input::file('fichero')->getRealPath();
Then this is what I should be sending to the Model, (just by intuition, never did it before)
(new document)->insertDocs($category, $title, $content, $path);
Does anyone know how this is done?
thank you very much
In your controller :
public function store()
{
// Upload file
$file = Input::file('fichero');
$destinationPath = 'uploads/folder';
$file->move($destinationPath);
// Create model
$model = new Model;
$model->category = Input::get('category');
$model->title = Input::get('title');
$model->content = Input::get('content');
$model->filename = $file->getClientOriginalName();
$model->destinationPath = $destinationPath;
// Save model
$model->save();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.