laravel-medialibrary: The current request does not have a file in a key named `avatar`
Hey guys, had encountered this problem… did not see anything wrong in my code to be honest… check it pls.
This is the form:
<div class="form-group row">
<label for="avatar" class="col-md-4 col-form-label text-md-right">{{ __('Avatar (optional)') }}</label>
<div class="col-md-6">
<input id="avatar" type="file" class="form-control" name="avatar">
</div>
</div>
this is the user model:
{
$this->addMediaConversion('thumb')
->width(60)
->height(60);
}
this is the RegisterController:
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'type' => $type,
]);
if (isset($data['avatar'])) {
$user->addMediaFromRequest('avatar')->toMediaCollection('avatars');
}
return $user;
filesystems.php:
'default' => env('FILESYSTEM_DRIVER', 'public'),
yes, the user model has:
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
class User extends \TCG\Voyager\Models\User
{
use Notifiable;
use HasMediaTrait;
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (6 by maintainers)
Does your opening form tag contain the right enctype?