Я пытаюсь загрузить файлы резюме и видео в одну из моих форм. Все работает, кроме имен файлов видео, которые не вставляются в мою таблицу видео. Они находятся в таблице, только имена столбцов в таблице Video, где должны храниться имена файлов: file_one, file_two, file_three - все null. Они правильно отображаются в моей папке public / videos. Резюме загружается правильно, как в общедоступных / резюме, так и в моей базе данных. Все вставляется в таблицу job_seeker_profiles.
AdminJobSeekerProfileController. php
public function store(JobSeekerProfileCreateRequest $request)
{
$input = $request->all();
$user = Auth::user();
if($file = $request->file('resume_id')) {
$name = time() . $file->getClientOriginalName();
$file->move('resumes', $name);
$resume = Resume::create(['file'=>$name]);
$input['resume_id'] = $resume->id;
}
if($file = $request->file('video_one_id')) {
$name = time() . $file->getClientOriginalName();
$file->move('videos', $name);
$video = Video::create(['file_one'=>$name]);
$input['video_one_id'] = $video->id;
}
if($file = $request->file('video_two_id')) {
$name = time() . $file->getClientOriginalName();
$file->move('videos', $name);
$video = Video::create(['file_two'=>$name]);
$input['video_two_id'] = $video->id;
}
if($file = $request->file('video_three_id')) {
$name = time() . $file->getClientOriginalName();
$file->move('videos', $name);
$video = Video::create(['file_three'=>$name]);
$input['video_three_id'] = $video->id;
}
$user->jobSeekerProfile()->create($input);
Alert::success('Your Profile has been created successfully!')->autoclose(5000);
return redirect('/admin/job-seeker/profile');
}
create.blade с формой
{!! Form::open(['method'=>'POST', 'action'=>'AdminJobSeekerProfileController@store', 'files'=>true]) !!}
<div class="form-group">
{!! Form::label('first_name', 'First Name:') !!}
{!! Form::text('first_name', null, ['class'=> $errors->first('first_name') ? 'border-danger form-control' : 'form-control']) !!}
<small class="text-danger">{{ $errors->first('first_name') }}</small>
</div>
<div class="form-group">
{!! Form::label('last_name', 'Last Name:') !!}
{!! Form::text('last_name', null, ['class'=> $errors->first('last_name') ? 'border-danger form-control' : 'form-control']) !!}
<small class="text-danger">{{ $errors->first('last_name') }}</small>
</div>
<div class="form-group">
{!! Form::label('email', 'Email:') !!}
{!! Form::email('email', null, ['class'=> $errors->first('email') ? 'border-danger form-control' : 'form-control']) !!}
<small class="text-danger">{{ $errors->first('email') }}</small>
</div>
<div class="form-group">
{!! Form::label('date_of_birth', 'Date of birth:') !!}
{!! Form::date('date_of_birth', null, ['class'=> $errors->first('date_of_birth') ? 'border-danger form-control' : 'form-control']) !!}
<small class="text-danger">{{ $errors->first('date_of_birth') }}</small>
</div>
<div class="form-group">
{!! Form::label('full_time', 'Full Time:') !!}
{!! Form::radio('full_or_part_time', 'Full Time', ['class'=>'form-control']) !!}
{!! Form::label('part_time', 'Part Time:') !!}
{!! Form::radio('full_or_part_time', 'Part Time', ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::hidden('user_id', Auth::user()->id, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('resume_id', 'Attach Resume:') !!}
{!! Form::file('resume_id', null, ['class'=> $errors->first('resume_id') ? 'border-danger form-control' : 'form-control']) !!}
<br><small class="text-danger">{{ $errors->first('resume_id') }}</small>
</div>
<h4>Please upload a few short videos (30 seconds max) for a better chance of being noticed. <small>(optional)</small></h4><br>
<div class="form-group">
{!! Form::label('video_one_id', '1. Tell us a little about yourself:') !!}
{!! Form::file('video_one_id', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('video_two_id', '2. Tell us about your past work experiences:') !!}
{!! Form::file('video_two_id', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('video_three_id', '3. What sets you apart?:') !!}
{!! Form::file('video_three_id', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('experience', 'Experience:') !!}
{!! Form::textarea('experience', null, ['class'=>'form-control', 'rows'=>'10', 'maxlength'=>'1000']) !!}
</div>
<div class="form-group">
{!! Form::label('additional_skills', 'Additional Skills (optional):') !!}
{!! Form::textarea('additional_skills', null, ['class'=>'form-control', 'rows'=>'3', 'maxlength'=>'250']) !!}
</div>
<div class="form-group">
{!! Form::submit('Create Profile', ['class'=>'btn btn-primary']) !!}
</div>
<br><br><br><br>
{!! Form::close() !!}
Видео. php модель:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Video extends Model
{
protected $uploads = '/videos/';
protected $fillable = ['file_one, file_two, file_three'];
//create an accessor
public function getFileAttribute($video){
return $this->uploads . $video;
}
public function jobSeekerProfile(){
return $this->belongsTo('App\JobSeekerProfile');
}
}