Я пытаюсь сделать регистрацию с загрузкой изображения профиля пользователя. (Я вынужден сделать это таким образом)
Я создал миграцию, как это: < /p>
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('nom');
$table->string('prenom');
$table->string('type')->default('visiteur');
$table->boolean('confirme')->default(false);
$table->string('email')->unique();
$table->string('password');
$table->string('photo_url')->default('default_photo_profile.jpg');
$table->rememberToken();
$table->timestamps();
});
< /code>
Функция создания: < /p>
$request = request();
if ($request->hasFile('photo')) {
$file = $request->file('photo');
$fullname=$data['nom'].'_'.date("Y-m-d",time()).'.'.$file->getClientOriginalExtension();
$path = $request->file('photo')->storeAs('images', $fullname);
}
return User::create([
'nom' => $data['nom'],
'prenom' => $data['prenom'],
'email' => $data['email'],
'photo_url' => $fullname,
'password' => Hash::make($data['password']),
]);
}
< /code>
и форма для поля файла похожа на это: < /p>
Photo profile
< /code>
Все работает нормально.
@csrf
Nom
@if ($errors->has('nom'))
{{ $errors->first('nom') }}
@endif
Prénom
@if ($errors->has('prenom'))
{{ $errors->first('prenom') }}
@endif
Email
@if ($errors->has('email'))
{{ $errors->first('email') }}
@endif
Mot de pass
@if ($errors->has('password'))
{{ $errors->first('password') }}
@endif
Mot de pass confirmation
Photo profile
Envoyer
< /code>
В чем проблема? < /p>
Подробнее здесь: https://stackoverflow.com/questions/513 ... ault-value