I have a weird problem: Uploading a image in local WORKS perfectly but when I upload to Production in digital ocean it does NOT.
Iam using laravel 11, vue 3 and InertiaJS
What happens in Production its that a zero 0 value its stored instead the usual path and the image does not. Another weird thing its that I have another form with POST method which already works on production. I tried to change this form to POST but still failing.
How front works: A button opens a modal and that action select a player who owns a photo. The player data its filled in the form and the input file allows to select new photo which its included in the Inertia JS form. In the useForm I include the _method: 'PUT'
because PHP has problemas sending files directly with PUT method and laravel allows override the POST method form.
- When The modal its opened by method
@click="openUpdatePlayer(user)"
the field photo its filled with the current photoformPlayer.photo = player.photo;
FILE Field
<TextInput
id="photo"
name="photo"
type="file"
placeholder = "Foto del jugador"
class="mt-1 block w-full border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm"
@input="formPlayer.photo = $event.target.files[0]"
/>
<PrimaryButton
class="ms-3"
:class="{ 'opacity-25': formPlayer.processing }"
:disabled="formPlayer.processing"
@click="updatePlayer()"
>
Actualizar
</PrimaryButton>
Form player
const formPlayer = useForm({ //I let just some fields for visualization purposes
weight: 0,
height: 0,
email: null,
photo: null,
_method: 'PUT'
});
Form code
const updatePlayer = () => {
formPlayer.post(route('playerUpdate', formPlayer.id), {
//onFinish: () => formPlayer.reset(),
onSuccess: () => closePlayerModal(),
});
};
CONTROLLER CODE
if ($request->hasFile('photo')) {
$image = $request->file('photo')->store('photos', 'public');
$user->photo = $image;
} else {
dd('error uploading photo', $request->file('photo'));
}