【发布时间】:2021-08-14 18:18:50
【问题描述】:
如何在我的控制器中创建一个 php 函数来保存由复选框指示的特定行?单击提交按钮时,需要将此行数据附加到 SQL 数据库。这是我迄今为止尝试过的,但它似乎不起作用
@extends('layouts.app')
@include('partialViews.navigation')
@section('content')
<div class="container">
<div class="row justify-content-center">
@yield('navigation')
<div class="col-md-8">
<div class="card">
<table id="example" class="data-table table table-striped">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Stage</th>
<th scope="col">Bedrijf</th>
<th scope="col">Afdeling</th>
<th scope="col">Locatie</th>
<th scope="col">Periode</th>
</tr>
</thead>
<tbody>
@foreach ($stagevoorstelen as $key => $stagevoorstel)
<tr>
<td scope="row">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="tableMaterialCheck2">
</div>
</td>
<td>{{$stagevoorstel->assignment->title ?? "stagair"}}</td>
<td>{{$stagevoorstel->companyContact1->department->company->name}}</td>
<td>{{$stagevoorstel->companyContact1->department->name ?? ""}}</td>
<td>{{$stagevoorstel->companyContact1->department->company->city}}</td>
<td>{{$stagevoorstel->assignment->year ?? ""}} {{$stagevoorstel->assignment->semester ?? ""}}</td>
</tr>
@endforeach
</tbody>
</table>
<div id="buttontjes">
<tr>
<td><button type="submit" id="btn-save" value="create" class="btn btn-sm">opslaan</button></td>
</tr>
</div>
</div>
</div>
</div>
</div>
@endsection
这是控制器,我不知道要在我的函数中添加什么!
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Repositories\Contracts\StageVoorstelRepository;
class student_bekijkstagesController extends Controller
{
/**
* @var StagevoorstelRepository
*/
private $stageVoorstel;
/**
* kaartjesWeergevenTestController Constructor
*
* @param StageVoorstelRepository $stagevoorstel
*/
public function __construct(StageVoorstelRepository $stageVoorstel)
{
//$this->middleware('auth');
$this->stageVoorstel = $stageVoorstel;
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('student_bekijkstages',['stagevoorstelen' => $this->stageVoorstel->getAvailableForStudents()]);
}
public function save(Request $request){
if($request->submit == "Save"){
}
}
}
【问题讨论】:
-
我没有看到表单 html 标记。是否包含在视图中??
-
我没用过!
标签: php html laravel visual-studio-code datatables