Level 46
You're declaring $image inside the if statement.
I am trying to add image with other stuffs to the database and struck here. The problem is when uploading image in database table.
Without image, everything is ok. here is my code:
public function store(CategoryRequest $request)
{
if ($request->hasFile('image')) {
$fileName = $request->file('image')->getClientOriginalExtension();
if ($request->file('image')->move('images/categories/', $fileName)) {
$image = $fileName;
}
}
Category::create([
'name' => $request->name,
'latin' => $request->latin,
'parent_id' => $request->parent_id,
'image' => $image,
]);
return redirect()->route('categories.index');
}
I get this error:
Undefined variable: image
Replace the following line:
'image' => $image,
with:
'image' => $image ?? null,
Please or to participate in this conversation.