On your form element you are missing the enctype. So change it to this:
<form method="POST" action="{{ action('RecipesController@store') }}" id="submitRecipeForm" enctype="multipart/form-data">
I have an image upload in one of my recipe applications that has been working fine up until this point. It suddenly broke and it will only allow me to post my recipe if I don't upload an image and I let it revert back to the default "noimage.jpg". Could somebody take a look at my ogic and see where I'm going wrong? I don't understand where it is breaking. Thank you.
Controller store function
// Handle File Upload
if($request->hasfile('recipeImage')){
// Get filename with extension
$fileameWithExt = $request->file('recipeImage')->getClientOriginalName();
// Get just filename
$filename = pathinfo($fileameWithExt, PATHINFO_FILENAME);
// Get just extension
$extension = $request->file('recipeImage')->getClientOriginalExtension();
// Filename to store
$fileNameToStore = $filename . '_' . time() . '.' . $extension;
// Upload Image
$path = $request->file('recipeImage')->storeAs('public/recipe_images', $fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
$recipe = new Recipe;
$recipe->author = auth()->user()->username;
$recipe->title = $request->input('title');
$recipe->description = $request->input('description');
$recipe->ingredients = $request->input('ingredients');
$recipe->directions = $request->input('directions');
$recipe->recipeImage = $fileNameToStore;
$recipe->prepTime = $request->input('prepTime');
$recipe->cookTime = $request->input('cookTime');
$recipe->servings = $request->input('servings');
$recipe->calories = $request->input('calories');
$recipe->user_id = auth()->user()->id;
$recipe->save();
Blade view with form
<form method="POST" action="{{ action('RecipesController@store') }}" id="submitRecipeForm">
<div class="photoUploadInput">
<label for="imageUpload">
<input type="file" id="imageUpload" name="recipeImage">
</label>
<span>Add a photo of your recipe!</span>
</div>
Let me know if you need to see anymore code. Thank you
On your form element you are missing the enctype. So change it to this:
<form method="POST" action="{{ action('RecipesController@store') }}" id="submitRecipeForm" enctype="multipart/form-data">
Please or to participate in this conversation.