我正在研究值班日志应用程序,管理员可以在其中输入组织中每个部门的日志(通常是Issues)。 我有一个阶梯式表单,其中有9个部门的9个字段集(在数据库中ID分别以相同的顺序编号。这9个步骤中的每个步骤都有3个输入(title,comment和interval)和一个next按钮,除了最后一个具有提交按钮。
预期结果是将表单插入日志表,日志标题,注释,时间间隔,user_id,department_id(此名称应与当前步骤所属的部门相同)
这是我的日志控制器:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Log;
use Auth;
use App\User;
use Illuminate\Http\Request;
class LogController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
//Display a listing of the resource.
public function index()
{
$logs = Log::all();
return view('logs.index',compact('logs'));
}
//Show the form for creating a new resource.
public function create()
{
return view('logs.create');
}
public function store(Request $request)
{
$validatedData = $request->validate([
'comment' => 'required|max:255','title' => 'required|max:50','department' => $request->department()->id,'user_id' => $request->user()->id,'time' => 'required|max:50',]);
$log = Log::create($validatedData);
return redirect('/logs')->with('success','log is successfully saved');
}
protected static function boot()
{
parent::boot();
static::creating(function ($query) {
$query->user_id = user()->id();
});
}
// Create the resoource
//Display the specified resource.
public function show(Log $log)
{
// In an admin panel,I usually don't need this method. It's often more efficient to
// show the log data in the edit view.
}
//Show the form for editing the specified resource.
public function edit($id)
{
$log = Log::findOrFail($id);
return view('logs.edit',compact('log'));
}
//Update the specified resource in storage.
public function update(Request $request,$id)
{
$validatedData = $request->validate([
'comment' => 'required|max:255',]);
Log::whereId($id)->update($validatedData);
return redirect('/logs')->with('success','Log is successfully updated');
}
//Remove the specified resource from storage.
public function destroy($id)
{
$log = Log::findOrFail($id);
$log->delete();
return redirect('/log')->with('success','Log is successfully deleted');
}
}
这里是部门负责人
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Department;
use Auth;
use App\User;
use Illuminate\Http\Request;
class DepartmentController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
//Display a listing of the resource.
public function index()
{
$departments = Department::all();
return view('departments.index',compact('departments'));
}
//Show the form for creating a new resource.
public function create()
{
$departments = Department::all();
return view('departments.create');
}
public function store(Request $request)
{
$validatedData = $request->validate([
'name' => 'required|max:255','head' => 'required|max:50',]);
$department = Department::create($validatedData);
return redirect('/departments')->with('success','department is successfully saved');
}
protected static function boot()
{
parent::boot();
static::creating(function ($query) {
$query->user_id = user()->id();
});
}
// Create the resoource
//Display the specified resource.
public function show(Department $department)
{
// In an admin panel,I usually don't need this method. It's often more efficient to
// show the department data in the edit view.
}
//Show the form for editing the specified resource.
public function edit($id)
{
$department = Department::findOrFail($id);
return view('departments.edit',compact('department'));
}
//Update the specified resource in storage.
public function update(Request $request,$id)
{
$validatedData = $request->validate([
'name' => 'required|max:255',]);
Department::whereId($id)->update($validatedData);
return redirect('/departments')->with('success','Department is successfully updated');
}
//Remove the specified resource from storage.
public function destroy(department $department)
{
$department->delete();
return redirect()->route('departments.index')
->with('success','Department deleted successfully');
}
}
我的创建日志视图:
<form role="form" class="registration-form" action="{{ route('logs.store')}}">
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3><span><i class="fa fa-calendar-check-o" aria-hidden="true"></i></span>Enter the Duty log for the Technical Department
</p>
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<input type="text" name="title" placeholder="Log Title" class="form-control" id="title" required>
</div>
<div class="form-group">
<input type="text" name="comment" placeholder="Log Details" class="form-control" id="comment" required>
</div>
<button type="button" class="btn btn-next">Next</button>
</div>
</fieldset>
.........其余7。
然后是最后一个
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3><span><i class="fa fa-calendar-check-o" aria-hidden="true"></i></span>Enter the Duty log for the I.T. Department
</p>
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<input type="text" name="title" placeholder="Log Title" class="form-control" id="title" required>
</div>
<div class="form-group">
<input type="text" name="comment" placeholder="Log Details" class="form-control" id="comment" required>
</div>
<button type="button" class="btn btn-previous">Previous</button>
<button type="submit" class="btn">Submit</button>
</div>
</fieldset>
这是我的jquery表单处理器:
$(document).ready(function () {
$('.registration-form fieldset:first-child').fadeIn('slow');
$('.registration-form input[type="text"]').on('focus',function () {
$(this).removeclass('input-error');
});
// next step
$('.registration-form .btn-next').on('click',function () {
var parent_fieldset = $(this).parents('fieldset');
var next_step = true;
parent_fieldset.find('input[type="text"],input[type="email"]').each(function () {
if ($(this).val() == "") {
$(this).addClass('input-error');
next_step = false;
} else {
$(this).removeclass('input-error');
}
});
if (next_step) {
parent_fieldset.fadeOut(400,function () {
$(this).next().fadeIn();
});
}
});
// previous step
$('.registration-form .btn-previous').on('click',function () {
$(this).parents('fieldset').fadeOut(400,function () {
$(this).prev().fadeIn();
});
});
// submit
$('.registration-form').on('submit',function (e) {
$(this).find('input[type="text"],input[type="email"]').each(function () {
if ($(this).val() == "") {
e.preventDefault();
$(this).addClass('input-error');
} else {
$(this).removeclass('input-error');
}
});
});
});
我尝试循环此部门表格,但偏移量为-1。
我对laravel还是陌生的,需要我能提供的所有帮助。 预先感谢。