I am having trouble calling a onclick function in the blade.php file below.
The function "newLogsStoreFromReason" is supposed to create logs, but nothings changes when the function is clicked.
English is not my first language, so if this post does not make sense to you or need more information, please leave your comments! Any advice would be appreciated! Thanks in advance!
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');