I'm totally a newbie in Laravel development. I have a few text files along with 1 video upload and thumbnail upload feature. I can save all the data into the DB, but I am stuck with video and thumbnail/image upload.
Controller
<?php
public function save(Request $request)
{
// Any other fields to be saved here..
$post = $request->all();
$v = \Validator::make($request->all(),
[
'title' => 'required',
'category' => 'required',
'description' => 'required',
'price' => 'required|Numeric',
'discount' => 'Numeric',
'thumbnail' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]
);
$file = Input::file('thumbnail');
$destinationPath = 'images/';
$filename = $file->getClientOriginalName();
Input::file('thumbnail')->move($destinationPath, $filename);
if ($v->fails()) {
return redirect()->back()->withErrors($v->errors());
} else {
$data = array(
'title' => $post['title'],
'category' => $post['category'],
'partner' => $post['partner'],
'description' => $post['description'],
'published' => $post['published'],
'featured' => $post['featured'],
'price' => $post['price'],
'discount' => $post['discount'],
'file' => "file",
'thumbnail' => $filename
);
$i = DB::table('items')->insert($data);
if ($i > 0) {
\Session::flash('message', 'new Item Saved');
return redirect('itemindex');
}
}
}
I added some code to test uploading images as a thumbnail but it failed.
View
<div class="form-group">
<label for="Thumbnail" class="col-md-3 control-label"></label>
<div class="timeline-item">
<div class="col-md-9 ">
<div class="timeline-body">
<img src="http://placehold.it/150x100" alt="..." class="margin">
</div>
</div>
</div>
</div>