This is my form controller to insert details with image in database table
public function store(Applicant $appl, ApplicantForm $request)
{
if($request->hasFile('ppimg_filename'))
{
$destinationPath="offerimages";
$file = $request->file('ppimg_filename');
$filename=$file->getClientOriginalName();
$request->file('ppimg_filename')->move($destinationPath,$filename);
}
$a=$appl->create($request->all());
$a['ppimg_filename'] = $filename;
return 'done';
}
What possibly could cause error:undefined filename
?
Looks like the script flow doesn't execute the code inside if statement.
Check ppimg_filename
in html form.
You define filename
inside an if
block. If the conditional expression does not evaluate to true then that block will not be entered and the variable will not be created. In that scenario the variable will not exist when you refer to it in the line $a['ppimg_filename'] = $filename;
. That is probably the reason for your error. You should either handle that case with an else
block that does not use any variables defined in your if
block, or create those variables before the if
block so that you can refer to them afterwards even if the block is not entered.