What line is throwing the error? Check the stack trace in the error
Aug 24, 2021
7
Level 3
Serialization of 'Illuminate\Http\UploadedFile' is not allowed
I've made a form with a drag-and-drop file upload option. The form submission fails with the error: Serialization of 'Illuminate\Http\UploadedFile' is not allowed
Form
@extends('base')
@section('content')
@component('components.titlebar', ['title' => $title])
@endcomponent
@include('components.notifications')
<fieldset>
<form action="{{ route('employee.store') }}" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="form-label" for="first_name">FIRST NAME:</label>
<input type="text" name="first_name" class="form-control" value="{{ old('first_name') }}" />
</div>
<div class="form-group">
<label class="form-label" for="last_name">LAST NAME:</label>
<input type="text" name="last_name" class="form-control" value="{{ old('last_name') }}" />
</div>
<div class="form-group">
<label class="form-label" for="department_id">DEPARTMENT:</label>
<select class="form-control" name="department_id">
@foreach($departments as $department)
<option value="{{ $department->ID }}">{{ $department->DESCRIPTION }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label class="form-label" for="email_address">EMAIL ADDRESS:</label>
<div class="input-group">
<input type="text" name="email_address" class="form-control" value="{{ old('email_address') }}" />
<div class="input-group-append">
<div class="input-group-text">@doublelglobal.com</div>
</div>
</div>
</div>
<div class="form-group">
<label class="form-label" for="mobile_number">MOBILE NUMBER:</label>
<!-- <input type="tel" name="mobile_number" class="form-control" value="{{ old('mobile_number') }}" /> -->
<div class="form-row">
<div class="col-md-3">
<input type="tel" name="area_code" class="form-control" maxlength="3" />
</div>
<div class="col-md-3">
<input type="tel" name="prefix" class="form-control" maxlength="3" />
</div>
<div class="col-md-6">
<input type="tel" name="number" class="form-control" maxlength="4" />
</div>
</div>
</div>
<div class="form-group">
<label class="form-label" for="phone_ext">PHONE EXTENSION:</label>
<input type="number" name="phone_ext" class="form-control" value="{{ old('phone_ext') }}" maxlength="3" />
</div>
<div class="drop-zone">
<span class="drop-zone-prompt">Drop a photo here or click to browse the computer</span>
<input type="file" name="employee_photo" class="drop-zone-input"/>
</div>
@csrf
@include('components.button', [
'classes' => ['btn-submit'],
'icon' => 'save',
'label' => 'SAVE'
])
</form>
</fieldset>
@endsection
Controller
private function cropProfileImage($path)
{
$image = Image::make($path)->resize(500,500);
$image->save($path, 40, 'jpg');
}
public function store(Request $request)
{
$validInput = $request->validate([
'first_name' => ['required', 'max:30', 'alpha'],
'last_name' => ['required', 'max:30', 'alpha_dash'],
'department_id' => ['required', 'exists:vmfg.DEPARTMENT,ID'],
'email_address' => ['nullable'],
'area_code' => ['nullable', 'size:3'],
'prefix' => ['nullable', 'size:3'],
'number' => ['nullable', 'size:4'],
'phone_ext' => ['nullable', 'integer', 'min:100', 'max:210', 'unique:employees,phone_ext' ],
'employee_photo' => ['required', 'image']
]);
$path = $request->file('employee_photo')->store('employee-photos');
$this->cropProfileImage($path);
$employee = new Employee;
$employee->first_name = $validInput['first_name'];
$employee->last_name = $validInput['last_name'];
$employee->department_id = $validInput['department_id'];
$employee->email_address = $validInput['email_address'] . '@doublelglobal.com';
$employee->phone_number = '+1' . $validInput['area_code'] . $validInput['prefix'] . $validInput['number'];
$employee->phone_ext = $validInput['phone_ext'];
$employee->photo_path = $path;
$employee->save();
return redirect()->route('employees.index')->with('success', 'The employee, ' . $employee->first_name . ' ' . $employee->last_name . ', was successfully added!');
}
What am I doing wrong?
Please or to participate in this conversation.