Can't assign string property to UploadedFile | How to do it properly? #779
Unanswered
anburocky3
asked this question in
Q&A
Replies: 2 comments 1 reply
-
@rubenvanassche Sorry for tagging you, i hope you are replying to all discussions. Any help on this would be super helpful. Thanks., |
Beta Was this translation helpful? Give feedback.
1 reply
-
I have the DTO data class like this. #[TypeScript]
class ContactInformationData extends Data
{
public function __construct(
public ?int $id,
public ?int $user_id,
#[Rule(['bail|nullable|image:mimes:jpeg,jpg,png,gif,svg|max:2048'])]
public UploadedFile $photo,
public ?string $created_at,
public ?string $updated_at,
) {
}
} And having this controller method public function storeStep7(ContactInformationData $data)
{
if (auth()->user()->contactInformation) {
// update the record
$contactInfo = ContactInformation::where('user_id', auth()->id())->first();
// search for filename and remove and store the file
if ($contactInfo->photo && $data->photo) {
$data->photo = $this->storeFile($contactInfo->photo, $data->photo->store('photos'));
// $data->document = $data->document->store('photos');
}
$contactInfo->update($data->toArray());
toast('Information updated!');
} else {
if ($data->photo) {
$data->photo = $data->photo->store('photos');
}
ContactInformation::updateOrCreate(['user_id' => auth()->id()], $data->toArray());
toast('Information saved!');
}
return to_route('dashboard');
} But since, I have to save the image path to the database.. What should i do now? Update: having mixed type was working. but having #[Rule(['bail|nullable|image:mimes:jpeg,jpg,png,gif,svg|max:2048'])]
public mixed $photo, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have this data file
HoroscopeInformationData.php
inapp/Data
folder.And tried to save this on controller like this.
What i want?
Beta Was this translation helpful? Give feedback.
All reactions