我正在使用PHP Laravel,Bootstrap,MySQL Phpmyadmin。我不太确定我哪里出了问题,因为我已经检查了数据属性,所有都是正确的,或者可能我遗漏了一些东西。
business.blade.php
@extends('layouts.apps')
@section('content')
<div class="col-sm-12 text-left ">
<h1 class="border-bottom border-bot pt-3">Businesses Information</h1>
</div>
<div class="Business-Content main-wrapper col-sm-12 text-left h-100 pr-0 pl-0 " >
<div class="col-sm-12 pl-0 pr-0 search-bars" >
<div class="topnav navbar navbar">
<div>
<button id="createbusiness" class="btn btn-success text-white " data-toggle="modal" data-target="#businessmodal">New Business <i class="fa fa-plus"></i></button>
<button id="bulkdelete" class="btn btn-danger text-white " style="margin-left:2px;" > <i class="fa fa-trash"></i></button>
</div>
<div class="modal fade" id="businessmodal" name="businessmodal" tabindex="-1" role="dialog" aria-labelledby="business-modal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modelHeading"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="businessform" class="modal-input">
{{ csrf_field() }}
<input type="hidden" name="business_id" id="business_id">
<div class="row">
<div class="col-sm-6">
<div class="row" style="margin-left: 0px;margin-right: 0px;">
<div class="col-sm-6" >
<label >Last Name</label>
<input type="text" class="form-control" name="lastname" id="lastname" placeholder="Ex: Mandreza" value="" required="">
<span id="lastname_err" class="text-danger error-text lastname_err"></span>
</div>
<div class="col-sm-6 ">
<label >First Name</label>
<input type="text" class="form-control" name="firstname" id="firstname" placeholder="Ex: Rodrigo" value="" required="">
<span id="firstname_err" class="text-danger error-text firstname_err"></span>
</div>
</div>
<div class="row" style="margin-left: 0px;margin-right: 0px;">
<div class="col-sm-6" >
<label >Middle Name</label>
<input type="text" class="form-control" name="middlename" id="middlename" placeholder="Ex: Exequiel" value="" required="">
<span id="middlename_err" class="text-danger error-text middlename_err"></span>
</div>
<div class="row" style="margin-left: 0px;margin-right: 0px;">
<div class="col-sm-6" >
<label >Telephone No.</label>
<input type="text" class="form-control" name="telephone" id="telephone" placeholder="Ex: 1234-5678" value="" required="">
<span id="telephone_err" class="text-danger error-text telephone_err"></span>
</div>
<div class="col-sm-6 ">
<label >Mobile No.</label>
<input type="text" class="form-control" name="mobile" id="mobile" placeholder="Ex: 0912-3456-789" value="" required="">
<span id="mobile_err" class="text-danger error-text mobile_err"></span>
</div>
</div>
</div>
<div class="row" style="margin-left: 0px;margin-right: 0px;">
<div class="col-sm-6" >
<label >Business Name</label>
<input type="text" class="form-control" name="businessname" id="businessname" placeholder="Ex: Sari-Sari Store" value="" required="">
<span id="businessname_err" class="text-danger error-text businessname_err"></span>
</div>
<div class="col-sm-6 ">
<label >Business Address</label>
<input type="text" class="form-control" name="businessaddress" id="businessaddress" placeholder="Ex: Namulandayan, Lupao" value="" required="">
<span id="businessaddress_err" class="text-danger error-text businessaddress_err"></span>
</div>
</div>
<div class="col-sm-3 ">
<label >Business Type</label>
<input type="text" class="form-control" name="businesstype" id="businesstype" placeholder="Ex: Partnership" value="" required="">
<span id="businesstype_err" class="text-danger error-text businesstype_err"></span>
</div>
</div>
<!----------------
-->
</div>
<div class="ln_solid"></div>
<div class="item form-group">
<div class="col-md-12 col-sm-12 offset-md-4">
<button type="submit" id="submit" class="btn btn-success business-button">Submit</button>
<a class="btn btn-primary" type="button" data-dismiss="modal" style="margin-left: 4px;" >Cancel</a>
<input class="btn btn-primary" type="reset" value="Reset">
</div>
</div>
</form>
</div>
<div class="modal-footer text-white">
</div>
</div>
</div>
</div>
<div class="search-container">
<input class="global_filter" type="text" id="global_filter" placeholder="Search..." name="search">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
<div class=" col-sm-12 text-left h-100 pr-0 pl-0 pt-2 pb-2 text-white" >
<div class="row pl-4 pr-4 ">
<div class="col-sm-12 border border-bot ">
</div>
</div>
<div class="row pt-4 pl-4 pr-4">
<div class=" col-sm-12 overflow-auto display-nones ">
<table class=" bulk_action dataTables_info table business-table datatable-element business table-striped jambo_table bulk_action text-center border dataTable no-footer">
<thead>
<tr class="headings">
<th >
<input class="icheckbox_flat-green" type="checkbox" id="check-all" >
</th>
<th class="column-title">Action</th>
<th class="column-title">Business_ID</th>
<th class="column-title">Last Name </th>
<th class="column-title">First Name </th>
<th class="column-title">Middle Name </th>
<th class="column-title">Mobile No.</th>
<th class="column-title">Business Name</th>
<th class="column-title">Business Type</th>
</th>
</tr>
</thead>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="businessviewmodal" name="businessviewmodal" tabindex="-1" role="dialog" aria-labelledby="business-modal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modelHeading">View Business Data</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="businessviewform" class="modal-input">
{{ csrf_field() }}
<input type="hidden" name="business_idv" id="business_idv">
<div class="row">
<div class="col-sm-6">
<div class="row" style="margin-left: 0px;margin-right: 0px;">
<div class="col-sm-6" >
<label >Last Name</label>
<input type="text" class="form-control" readonly id="lastnamev" name="lastnamev" readonly>
</div>
<div class="col-sm-6 ">
<label >First Name</label>
<input type="text" class="form-control" id="firstnamev" name="firstnamev" readonly >
</div>
</div>
<div class="row" style="margin-left: 0px;margin-right: 0px;">
<div class="col-sm-6" >
<label >Middle Name</label>
<input type="text" readonly class="form-control" name="middlenamev" id="middlenamev" >
</div>
<div class="row" style="margin-left: 0px;margin-right: 0px;">
<div class="col-sm-6" >
<label >Telephone No.</label>
<input type="text" class="form-control" readonly name="telephonev" id="telephonev" >
</div>
<div class="col-sm-6 ">
<label >Mobile No.</label>
<input type="text" class="form-control" readonly name="mobilev" id="mobilev" >
</div>
</div>
<div class="item form-group">
<label class="col-form-label col-md-3 col-sm-3 label-align" for="first-name">Business Name
</label>
<div class="col-md-12 col-sm-12 ">
<input type="text" id="businessnamev" readonly name="businessnamev" class="form-control ">
</div>
</div>
<div class="item form-group">
<label class="col-form-label col-md-3 col-sm-3 label-align" >Business Address
</label>
<div class="col-md-12 col-sm-12 ">
<input type="text" id="businessaddressv" readonly name="businessaddressv" class="form-control ">
</div>
</div>
<div class="item form-group">
<label class="col-form-label col-md-3 col-sm-3 label-align" for="first-name">Business Type
</label>
<div class="col-md-12 col-sm-12 ">
<input type="text" id="businesstypev" readonly name="businesstypev" class="form-control ">
</div>
</div>
</div>
@endsection
数据信息不能在系统本身录入,业务信息控制器就是这样。
<?php
namespace App\Http\Controllers\AdminPanel;
use App\Http\Controllers\Controller;
//Models
use App\Models\business_info;
use Illuminate\Http\Request;
//Plugins
use Yajra\DataTables\DataTables;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Carbon\Carbon;
use PDF;
class BusinessInfoController extends Controller
{
public function index(Request $request)
{
if (!session()->has("user")) {
return redirect("login");
}
$business = business_info::latest()->get();
if ($request->ajax()) {
$data = business_info::latest()->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('checkbox', function($row){
$chk = '
<input type="checkbox" class="flat icheckbox_flat-green text-center checkBoxClass" id="checked" name="ids" data-id="'.$row->business_id.'" name="table_records">';
return $chk;
})
->addColumn('action', function($row){
$btn = '<a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->business_id.'" data-original-title="Edit" class="edit btn btn-info btn-xs pr-4 pl-4 editBusiness"><i class="fa fa-pencil fa-lg"></i> </a>';
$btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->business_id.'" data-original-title="Delete" class="btn btn-danger btn-xs pr-4 pl-4 deletebusiness"><i class="fa fa-trash fa-lg"></i> </a>';
$btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->business_id.'" data-original-title="View" class="btn btn-primary btn-xs pr-4 pl-4 viewbusiness"><i class="fa fa-folder fa-lg"></i> </a>';
return $btn;
})
->rawColumns(['checkbox','action'])
->make(true);
}
return view('pages.AdminPanel.business',[compact('business')]);
}
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'lastname' => 'required',
'firstname' => 'required',
'middlename' => 'required',
'telephone' => 'required',
'mobile' => 'required',
'businessname' => 'required',
'businessaddress' => 'required',
'businesstype' => 'required',
]);
if ($validator->fails()) {
return response()->json(['status'=>0,'error'=>$validator->errors()]);
}else{
business_info::updateOrCreate(['business_id' => $request->business_id],
['lastname' => $request->lastname,
'firstname' => $request->firstname,
'middlename'=> $request->middlename,
'telephone_no'=>$request->telephone,
'mobile_no'=>$request->mobile,
'businessname'=>$request->businessname,
'businessaddress'=>$request->businessaddress,
'businesstype'=>$request->businesstype]);
return response()->json(['status'=>1,'success'=>'Business saved successfully.']);
}
}
public function budget($business_id)
{
$budget_involve = DB::table('budget_involves')
->where('business_id','=',$business_id)
->get();
return response()->json($budget_involve);
}
public function edit($id)
{
$business_info = business_info::find($id);
return response()->json($business_info);
}
}
这是web.php部分
<?php
use Illuminate\Support\Facades\Route;
//Business Module
use App\Http\Controllers\AdminPanel\BusinessInfoController;
//Business Module
Route::resource('business', BusinessInfoController::class);
Route::get('business/budget/{business_id}', [BusinessInfoController::class, 'budget']);
这是custom.js部分
// business show table
var table = $('.business-table').DataTable({
processing: true,
dom: 'lrtip',
serverSide: true,
ajax: config.routes.business,
columns: [{
data: 'checkbox',
name: 'checkbox',
orderable: false,
searchable: false
},{
data: 'action',
name: 'action',
orderable: false,
searchable: false
},{data: 'business_id',name: 'business_id', "visible": false,
},{data: 'lastname',name: 'lastname'
},{data: 'firstname',name: 'firstname'
},{data: 'middlename',name: 'middlename'
},{data: 'mobile_no',name: 'mobile_no'
},{data: 'business name',name: 'businessname'
},{data: 'businesstype',name: 'businesstype'
},
]
});
//Business module CreateBusiness POPUP
$('#createbusiness').click(function() {
$('#submit').val("create-business");
$('#businessform').trigger("reset");
$('#modelHeading').html("Create Business Data");
$('#businessmodal').modal('show');
$('#lastname_err').html("");
$('#firstname_err').html("");
$('#middlename_err').html("");
$('#telephone_err').html("");
$('#mobile_err').html("");
$('#businessname').html("");
$('#businessaddress').html("");
$('#businesstype').html("");
});
//Business module BusinessEdit
$('body').on('click', '.editBusiness', function() {
var business_id = $(this).data('id');
$.get(config.routes.business + '/' + business_id + '/edit', function(data) {
$('#modelHeading').html("Modify Business Data");
$('#submit').val("Edit Business");
$('#businessmodal').modal('show');
$('#business_id').val(data.business_id);
$('#lastname').val(data.lastname);
$('#firstname').val(data.firstname);
$('#middlename').val(data.middlename);
$('#telephone').val(data.telephone_no);
$('#mobile').val(data.mobile_no);
$('#businessname').val(data.businessname);
$('#businessaddress').val(data.businessaddress);
$('#businesstype').val(data.businesstype);
// $('#author').val(data.author);
});
});
//Business module viewmodal
$('body').on('click', '.viewbusiness', function() {
var business_id = $(this).data('id');
$.get(config.routes.business + '/' + business_id + '/edit', function(data) {
$('#modelHeading').html("View Business Data");
$('#submit').val("Edit Business");
$('#businessviewmodal').modal('show');
$('#business_idv').val(data.business_id);
$('#lastnamev').val(data.lastname);
$('#firstnamev').val(data.firstname);
$('#middlenamev').val(data.middlename);
$('#telephonev').val(data.telephone_no);
$('#mobilev').val(data.mobile_no);
$('#businessnamev').val(data.businessname);
$('#businessaddressv').val(data.businessaddress);
$('#businesstypev').val(data.businesstype);
});
});
//BUTTOM SUBMIT MODAL
$('#submit').click(function(e) {
e.preventDefault();
$(this).html('Save');
$(this).html('Submit');
$.ajax({
data: $('#businessform').serialize(),
url: config.routes.business_store,
type: "POST",
dataType: 'json',
success: function(data) {
if(data.status == 1){
$('#businessmodal').modal('hide');
$('#businessform').trigger("reset");
table.draw();
}else{
printErrorMsg(data.error);
}
}/*,
error: function(data) {
console.log('Error:', data);
$('#submit').html('Save Changes');
}
*/
});
});
//delete table
$('body').on('click', '.deletebusiness', function () {
var business_id = $(this).data("id");
if (confirm("Are You sure want to delete !")) {
$.ajax({
type: "DELETE",
url: config.routes.business_store +'/'+business_id,
success: function (data) {
table.draw();
},
error: function (data) {
console.log('Error:', data);
}
});
}
});
//Bulk Delete check all
$('#check-all').click(function(){
$('.checkBoxClass').prop('checked', $(this).prop('checked'));
});
// Bulk Delete Current Select
$('#bulkdelete').click(function(e){
e.preventDefault();
var total=0;
$("input:checkbox[name=ids]:checked").each(function(){
total += 1;
});
if (confirm("Number of Data to Delete: " + total)) {
$("input:checkbox[name=ids]:checked").each(function(){
var business_id = $(this).data("id");
$.ajax({
type: "DELETE",
url: config.routes.business_store +'/'+business_id,
success: function (data) {
table.draw();
},
error: function (data) {
console.log('Error:', data);
}
});
});
}
});
提前感谢那些能够帮助我的人!
1条答案
按热度按时间iqjalb3h1#
在custom.js中将“业务名称”更改为“业务名称”