Я использую Laravel -5,8 для моего проекта полей ввода динамических c. Я использую mysql базу данных.
Правила:
StoreAppraisalGoalRequest
public function rules()
{
return [
'goal_type_id' => Rule::unique('appraisal_goals')->where(function ($query) {
return $query->where('appraisal_identity_id', $this->appraisal_identity_id)
->where('goal_type_id', $this->goal_type_id)
->where('employee_id', $this->employee_id);
}),
'goal_title' => Rule::unique('appraisal_goals')->where(function ($query) {
return $query->where('appraisal_identity_id', $this->appraisal_identity_id)
->where('goal_title', $this->goal_title)
->where('employee_id', $this->employee_id);
}),
'appraisal_doc' => 'nullable|mimes:doc,docx,xls,xlsx,ppt,pptx,pdf,jpg,jpeg,bmp,png,|max:5000',
'weighted_score' => 'required|numeric|min:0|max:500',
'kpi_description' => 'required|array',
'kpi_description.*' => 'required',
'activity' => 'required|array',
'activity.*' => 'required',
'start_date.*' => [
'required',
'date',
'date_format:Y-m-d',
],
'end_date.*' => [
'required',
'date',
'date_format:Y-m-d',
'after:start_date.*'
],
];
}
Две задействованные таблицы:
- appraisal_goals
- appraisal_goal_details
appraisal_goals - это главная таблица.
Модели:
AppraisalGoal
class AppraisalGoal extends Model
{
use Notifiable;
public $timestamps = false;
protected $table = 'appraisal_goals';
protected $fillable = [
'id',
'goal_type_id',
'parent_id',
'appraisal_identity_id',
'employee_id',
'company_id',
'is_published',
'is_approved',
'weighted_score',
'employee_comment',
'line_manager_comment',
'goal_title',
'appraisal_doc',
'appraisal_start_date',
'appraisal_end_date',
];
protected $dates = [];
protected $casts = [];
public function goaltype()
{
return $this->belongsTo('App\Models\Appraisal\AppraisalGoalType','goal_type_id');
}
public function employee()
{
return $this->belongsTo('App\Models\Hr\HrEmployee','employee_id');
}
public function appraisalidentity()
{
return $this->belongsTo('App\Models\Appraisal\AppraisalIdentity','appraisal_identity_id');
}
public function appraisalgoaldetail(){
return $this->hasMany('App\Models\Appraisal\AppraisalGoalDetail');
}
public function appraisalgoalcomment(){
return $this->hasMany('App\Models\Appraisal\AppraisalGoalComment');
}
}
AppraisalGoalDetail
class AppraisalGoalDetail extends Model
{
protected $table = 'appraisal_goal_details';
protected $fillable = [
'name',
'company_id',
'appraisal_goal_id',
'kpi_description',
'appraisal_doc',
'activity',
'start_date',
'end_date',
'appraisal_identity_id',
'employee_id',
];
public function appraisalgoal()
{
return $this->belongsTo('App\Models\Appraisal\AppraisalGoal');
}
}
Контроллер
public function store(StoreAppraisalGoalRequest $request)
{
$appraisalStartDate = Carbon::parse($request->appraisal_start_date);
$appraisalEndDate = Carbon::parse($request->appraisal_end_date);
$userCompany = Auth::user()->company_id;
$employeeId = Auth::user()->employee_id;
$identities = DB::table('appraisal_identity')->select('id','appraisal_name')->where('company_id', $userCompany)->where('is_current', 1)->first();
$employees = DB::table('hr_employees')->select('id')->where('id', $employeeId)->first();
try {
$goal = new AppraisalGoal();
$goal->goal_type_id = $request->goal_type_id;
$goal->appraisal_identity_id = $request->appraisal_identity_id;
$goal->employee_id = $request->employee_id; //$employeeId; //$request->employees_id
$goal->weighted_score = $request->weighted_score;
$goal->goal_title = $request->goal_title;
$goal->goal_description = $request->goal_description;
if ($request->appraisal_doc != "") {
$appraisal_doc = $request->file('appraisal_doc');
$new_name = rand() . '.' . $appraisal_doc->getClientOriginalExtension();
$appraisal_doc->move(public_path('storage/documents/appraisal_goal'), $new_name);
// $arr['appraisal_doc'] = $new_name;
$goal->appraisal_doc = $new_name;
}
$goal->save();
foreach ( $request->activity as $key => $activity){
$startDate = Carbon::parse($request->start_date[$key]);
$endDate = Carbon::parse($request->end_date[$key]);
$goaldetail = new AppraisalGoalDetail();
$goaldetail->kpi_description = $request->kpi_description[$key];
$goaldetail->appraisal_doc = $request->application_doc[$key];
$goaldetail->activity = $request->activity[$key];
$goaldetail->start_date = $startDate ->toDateTimeString();
$goaldetail->end_date = $endDate->toDateTimeString();
$goaldetail->appraisal_goal_id = $goal->id;
$goaldetail->appraisal_identity_id = $goal->appraisal_identity_id;
$goaldetail->employee_id = $goal->employee_id;
$goaldetail->save();
}
$min_date = AppraisalGoalDetail::select('start_date')->where('appraisal_goal_id', $goal->id)->min('start_date');
$max_date = AppraisalGoalDetail::select('end_date')->where('appraisal_goal_id', $goal->id)->max('end_date');
$parentid = AppraisalGoalType::select('parent_id')->whereNotNull('parent_id')->where('company_id', $userCompany)->where('id', $goal->goal_type_id)->first();
$goal->update([
'appraisal_start_date' => $min_date,
'appraisal_end_date' => $max_date,
'parent_id' => $parentid->parent_id
]);
Session::flash('success', 'Appraisal Goal is created successfully');
return redirect()->route('appraisal.appraisal_goals.index');
} catch (Exception $exception) {
Session::flash('danger', 'Appraisal Goal creation failed!');
return redirect()->route('appraisal.appraisal_goals.index');
}
}
view: appraisal_goals
create.blade
<form action="{{route('appraisal.appraisal_goals.store')}}" method="post" class="form-horizontal" enctype="multipart/form-data">
{{csrf_field()}}
<div class="card-body">
<div class="form-body">
<div class="row">
<div class="col-12 col-sm-6">
<div class="form-group">
<label class="control-label"> Goal Type:<span style="color:red;">*</span></label>
<select id="goal_type" class="form-control" name="goal_type_id">
<option value="">Select Goal Type</option>
@foreach ($categories as $category)
@unless($category->name === 'Job Fundamentals')
<option hidden value="{{ $category->id }}" {{ $category->id == old('category_id') ? 'selected' : '' }}>{{ $category->name }}</option>
@if ($category->children)
@foreach ($category->children as $child)
@unless($child->name === 'Job Fundamentals')
<option value="{{ $child->id }}" {{ $child->id == old('category_id') ? 'selected' : '' }}> {{ $child->name }}</option>
@endunless
@endforeach
@endif
@endunless
@endforeach
</select>
</div>
</div>
<input type="hidden" name="appraisal_identity_id" value="{{$identities->id}}">
<input type="hidden" name="employee_id" value="{{$employees->id}}">
<input type="hidden" id="max_score" class="form-control" >
<input type="hidden" id="weighted_score" class="form-control" value="0" >
<div class="col-12 col-sm-6">
<div class="form-group">
<label class="control-label"> Goal Title:<span style="color:red;">*</span></label>
<input type="text" name="goal_title" placeholder="Enter goal title here" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label>Goal Description</label>
<textarea rows="2" name="goal_description" class="form-control" placeholder="Enter Goal Description here ..."></textarea>
</div>
</div>
<div class="col-sm-12">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Activity<span style="color:red;">*</span></th>
<th scope="col">KPI<span style="color:red;">*</span></th>
<th scope="col">Start Date<span style="color:red;">*</span></th>
<th scope="col">End Date<span style="color:red;">*</span></th>
<th scope="col"><a class="btn btn-info addRow"><i class="fa fa-plus"></i></a></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="activity[]" class="form-control activity" ></td>
<td><input type="text" name="kpi_description[]" class="form-control kpi_description" ></td>
<td><input type="date" class="form-control start_date" placeholder="dd/mm/yyyy" name="start_date[]" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}"></td>
<td><input type="date" class="form-control end_date" placeholder="dd/mm/yyyy" name="end_date[]" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}"></td>
<td><a class="btn btn-danger remove"> <i class="fa fa-times"></i></a></td>
</tr>
</tbody>
</table>
</div>
<div class="col-12 col-sm-6">
<div class="form-group">
<label class="control-label"> Weight(%):<span style="color:red;">*</span></label>
<input type="number" name="weighted_score" id="total_weighted_score" placeholder="Enter weighted score here" class="form-control" max="120" onkeyup="checkScore(this.value)">
</div>
</div>
<div class="col-12 col-sm-6">
<div class="form-group">
<label class="control-label"> Attachment:</label>
<div class="custom-file">
<input type="file" name="appraisal_doc" class="custom-file-input" id="customFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">{{ trans('global.save') }}</button>
<button type="button" onclick="window.location.href='{{route('appraisal.appraisal_goals.index')}}'" class="btn btn-default">Cancel</button>
</div>
</form>
script
<script type="text/javascript">
$(document).ready(function(){
$('.addRow').on('click', function () {
var isHod = {{ Auth::user()->is_hod == 0 ? 0 : 1 }};
var numRows = $('.activity').length
if (numRows<4) {
addRow();
}
});
function addRow() {
var addRow = '<tr>\n' +
' <td><input type="text" name="activity[]" class="form-control activity" ></td>\n' +
' <td><input type="text" name="kpi_description[]" class="form-control kpi_description" ></td>\n' +
' <td><input type="date" class="form-control start_date" placeholder="dd/mm/yyyy" name="start_date[]" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}"></td>\n' +
' <td><input type="date" class="form-control end_date" placeholder="dd/mm/yyyy" name="end_date[]" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}"></td>\n' +
' <td><a class="btn btn-danger remove"> <i class="fa fa-times"></i></a></td>\n' +
' </tr>';
$('tbody').append(addRow);
addRemoveListener();
};
addRemoveListener();
});
</script>
Когда я нажимаю кнопку подтверждения Я ожидал, что данные будут сохранены в appraisal_goals и appraisal_goal_details. В локальной системе все работает отлично. Однако при развертывании в Digital Ocean данные сохранялись только в appraisal_goals, но не сохранялись в appraisal_goal_detail.
Это происходит только на сервере цифрового океана.
Почему?
Как я могу решить это.
Спасибо