Hello, after sending the form, the photo is saved in the storage/app/ folder, but in the database it is saved as a system path (C:/user/appdata/local/temp etc...). How to fix it?
when trying to display a photo on the website, I get an error: Not allowed to load local resource
export default function PersonalInfo({ mustVerifyEmail, status, progress }) {
const user = usePage().props.auth.user;
const { data, setData, post, errors, processing, recentlySuccessful } =
useForm({
name: user.name,
surname: user.surname,
email: user.email,
address: user.address,
phone_number: user.phone_number,
profile_image_path: user.profile_image_path,
});
const submit = (e) => {
e.preventDefault();
post(route("profile.update"));
};
return (
<label
htmlFor="image_picker"
className="image-picker-label"
>
<p>Wybierz zdjęcie profilowe </p>
<FontAwesomeIcon icon={faImage} />
</label>
<input
type="file"
id="image_picker"
hidden
onChange={(e) =>
setData("profile_image_path", e.target.files[0])
}
/>
<InputError message={errors.profile_image_path} />
)
profile controler:
public function update(ProfileUpdateRequest $request, User $user): RedirectResponse
{
$request->user()->fill($request->validated());
if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null;
}
if($request->hasFile('profile_image_path')){
if($user->profile_image_path){
Storage::delete($user->profile_image_path);
}
$file = $request->file('profile_image_path');
$name = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
$ext = $file->getClientOriginalExtension();
$user->profile_image_path = $request->file( 'profile_image_path' )->storeAs( 'public', $name . $ext );
}
$request->user()->save();
return Redirect::route('profile.edit');
}
I have already entered php artisan storage:link