这是我的index.blade.php代码:
Odd
这是我的ajaxcontroller.php代码:
@extends('adminlte::page')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Companies</div>
<div class="panel-body">
<form action="{{url("/delete")}}" method="post">
{!!csrf_field()!!}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">Add Company</button><br><br>
<table id="data_table" class="display">
<thead>
<tr>
<th>Checkbox</th>
<th>Company ID</th>
<th>Name</th>
<th>Status</th>
<th>Created at</th>
<th>Updated at</th>
<!-- <<th>Edit</th>
<th>Delete</th> -->
</tr>
</thead>
<tbody>
@foreach ($companies as $key => $com)
<tr>
<td>
<input type="checkbox" name="multi_id[]" value="{{$com->id}}">
</td>
<td>{{$com->id}}</td>
<td>{{$com->company_name}}</td>
<td>{{$com->status}}</td>
<td>{{$com->created_at}}</td>
<td>{{$com->updated_at}}</td>
<!-- <td>
<a href="#" class="edit-model" data-id="{{$com->id}}" data-company_name="{{$com->comapany_name}}" data-status="{{$com->status}}">
<i class="glyphicon glyphicon-pencil"></i>
</a>
</td>
<td>
<a href="#" class="delete-model" data-id="{{$com->id}}" data-company_name="{{$com->comapany_name}}" data-status="{{$com->status}}">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td> -->
</tr>
@endforeach
</tbody>
</table>
<button type="submit" class="btn btn-link" name="action" value="delete"><i class="glyphicon glyphicon-trash"></i></button>
<button type="submit" class="btn btn-link" name="action" value="save"><i class="glyphicon glyphicon-pencil"></i></button>
</form>
</div>
</div>
</div>
</div>
这是我的路线:
<?php
namespace App\Http\Controllers;
use Validator;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\companies;
use App\User;
class AjaxController extends Controller
{
public function index()
{
$companies = companies::all();
$user = User::all();
return view('ajax.index',compact('companies'));
}
public function delete(Request $request)
{
switch ($request->input('action')) {
case 'delete':
$multi_id = $request->input('multi_id');
companies::whereIn('id',$multi_id)
->delete();
return redirect('/companies')->with('success','deleted');
break;
case 'save':
$companies = companies::findOrFail($request->company_id);
$companies->update($request->all());
return redirect('/companies')->with('success','updated');
break;
// case 'advanced_edit':
// // Redirect to advanced edit
// break;
}
}
}
我要编辑多行并使用“保存”按钮更新所有行, 我怎样才能做到这一点?请任何人在这种情况下都可以帮助我。在“删除”功能中,“保存”是我的更新功能。我也处于起步阶段。