我在下面的blade.php文件中调用onclick函数时遇到了问题。
函数“newLogsStoreFromReason”应该创建日志,但是当单击该函数时nothings会改变。
英语不是我的第一语言,所以如果这篇文章对您没有意义或需要更多信息,请留下您的意见!任何意见,将不胜感激!提前谢谢!
reasons_create.blade.php
{!! Form::open(['action' => 'AdminController@newLogsStoreFromReason']) !!}
@foreach($reasons as $reason)
{!! Form::hidden('id', $reason->id) !!}
{!! Form::hidden('courseId', $reason->course_id) !!}
<ul>
<b>Course:: </b> {{$reason->course_name}}
</ul>
<ul>
<b>Reason::</b> {{$reason->content}}
</ul>
<div class = "form-group">
<ul>
<b>Weeks Requested:: </b>{{$reason->weeks_requested}}
{!! Form::hidden('weeks_requested', $reason->weeks_requested) !!}
</ul>
</div>
<ul>
<b>Status::</b>
{{$reason->status}}
</ul>
<div class = "form-group">
<ul>
<b>Time when {{$requester->first_name}} {{$requester->last_name}} requested::</b>
{!! Form::hidden('userId', $requester->id) !!}
{{$reason->created_at}}
</ul>
</div>
<hr />
@endforeach
**Nothing happens when this button is clicked**
<div class = "form-group">
{!! Form::submit('Create Logs', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
AdminController.php
public function newLogsStoreFromReason(CreateJournalRequest $request){
$userId = $request->input('userId');
$courseId = $request->input('courseId');
// get the number of weeks and convert it to int type
$weeks = $request->input('weeks_requested');
$weeksCount = intval($weeks);
$lastLog = Log::where('course_id', $courseId)->where('user_id', $userId)->get()->last();
$lastNumber = intval($lastJournal->weeks);
$total = $lastNumber + $weeksCount;
$newLogs = array();
for($i = $lastNumber + 1; $i <= $total; $i++){
array_push($newLogs, array(
'user_id' => $userId,
'course_id' => $courseId,
'weeks' => $i,
'work_description' => '',
'instructor_comments' => '',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
));
}
Journal::insert($newLogs);
return redirect('/admin/home');
}
Route.php
Route::post('logs', 'AdminController@newLogsStoreFromReason');