where did the class validate come from ??
Posted: Mon Jan 09, 2017 9:57 am
I was just going through this article here on how to upload images in laravel: http://devartisans.com/articles/image-upload-laravel-5 .
I see the below function in the article:
I don't quite understand the below method:
where did the validate method come into the class ??
I believe that line of code is checking if the fields title and image are populated , but where did the class validate come from ??
Thank you.
Gautam.
I see the below function in the article:
Code: Select all
public function store(Request $request)
{
$image = new Image();
$this->validate($request, [
'title' => 'required',
'image' => 'required'
]);
$image->title = $request->title;
$image->description = $request->description;
if($request->hasFile('image')) {
$file = Input::file('image');
//getting timestamp
$timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
$name = $timestamp. '-' .$file->getClientOriginalName();
$image->filePath = $name;
$file->move(public_path().'/images/', $name);
}
$image->save();
return $this->create()->with('success', 'Image Uploaded Successfully');
}
Code: Select all
$this->validate($request, [
'title' => 'required',
'image' => 'required'
]);
I believe that line of code is checking if the fields title and image are populated , but where did the class validate come from ??
Thank you.
Gautam.