Unable to save data in database laravel - php

I have a problem , saving data to the database from the input form that I made. The code is running well but the form is not saving the data I input from the form to the database. Did I miss something? when I click on the button to save the info to the database, nothing seems to happen(meaning no error).
Here is my jquery:
var percentageSupport = "";
$('#btnSaveFinanicialSupport').on('click', function () {
if (patientId == "") {
alert("kindly Enter Patient Id ")
return false;
}
if ($('#currentSupport').val() == 0) {
alert('Kindly Give Financial Support');
return false;
}
var totalPayableAmount = $('#payableAmount').val();
var currentSupportAmount = $('#currentSupport').val();
if (currentSupportAmount > totalPayableAmount) {
alert('Kindly Enter Correct Support Amount');
return false;
}
//here to start to set data to call save service.
var percantageSupportAmount = Math.round((currentSupportAmount / totalPayableAmount) * 100);
var supportType = $('select.supportType').val();
var token = supportType.split("#");
var supportTypeId = token[0];
var supportType = token[1];
if (supportType == "SELECT") {
alert('kindly Select Support Type');
return false;
}
var comments = $('#comments').val();
var orderIds = $("#tbody input:checkbox:checked").map(function () {
return $(this).attr("orderId");
}).get();
var serviceIds = $("#tbody input:checkbox:checked").map(function () {
return $(this).attr("serviceId");
}).get();
var serviceCost = $("#tbody input:checkbox:checked").map(function () {
return $(this).attr("price");
}).get();
var servicePayableAmount = $("#tbody input:checkbox:checked").map(function () {
return $(this).attr("payableAmount");
}).get();
var serviceFinancialSupport = $("#tbody input:checkbox:checked").map(function () {
return $(this).attr("financialSupport");
}).get();
$.ajax({
type: 'post',
data: {
patientId: patientId, supportTypeId: supportTypeId, percantageSupportAmount: percantageSupportAmount,
comments: comments, serviceIds: serviceIds, orderIds: orderIds, servicePayableAmount: servicePayableAmount,
serviceFinancialSupport: serviceFinancialSupport, serviceCost: serviceCost
},
url: '/saveFinancialSupport',
success: function (data) {
alert("Financial Support Given Successfully")
$("#tbodyy").html("");
$("#tbody").html("");
$('#totalAmount').val('');
$('#totalAmount').text('');
$('#paidAmount').val('');
$('#paidAmount').text('');
$('#supportamount').val('');
$('#supportamount').text('');
$('#comments').val('');
$('#comments').text('');
$('#totalamount').val('');
$('#totalamount').text('');
$('#totalpayable').val('');
$('#totalpayable').text('');
}
});
})
Here is my controller:
//save financial support
public function saveFinancialSupport(Request $req){
$output = array();
$orderIds = $req->orderids;
$serviceIds = $req->serviceids;
$servicePayableAmount = $req->servicePayableAmount;
$serviceFinancialSupport = $req->serviceids;
$serviceCost = $req->serviceCost;
$obj = new SessionClass();
$array = array();
for ($i=0; $i < count($orderIds) ; $i++) {
$price = $serviceCost[$i];
$support = ($servicePayableAmount[$i] * $req->percentageSupport)/100;
$array[$i] = array(
"financialSupport" => $support,
"patientId" => $req->patientId,
"orderId" => $orderIds[$i],
"supportTypeId" => $req->supportTypeId,
"price" => $serviceCost[$i],
"sign" => "+",
"percentageSupport" => $req->percentageSupport,
"comments" => $req->comments,
"active" => "Y",
"refFormNo" => "0",
"serviceId" => $serviceids[$i],
"id" => "123",
"locationId" => $obj->getLocationId(),
"orgId" => $obj->getOrgId(),
"sessionId" => $obj->getSessionId(),
"crtdBy" => $obj->getUserId(),
"crtdTerminalId" => "123");
}
$host = new HostClass();
$obj = new SessionClass();
$data = json_encode($array);
$response = Http::post('127.0.0.1:9000/saveFinancialSupport', $array);
return redirect()->back()->with('alert', 'Record Save Successfully');
}
Here is my web route:
Route::post('saveFinancialSupport' , 'SupportController#saveFinancialSupport');
Here is my web route:
#extends('layouts.theme')
#section('content')
<meta name="csrf-token" content="{{ csrf_token() }}">
<div class="container custom-container">
#include('patientPanel.patientPanel')
<form method="post" action="saveFinancialSupport" id="fsform">
#csrf
<div class="card mb-2">
<div class="card-body pb-2">
<div class="row">
<div class="col-lg-1">
<label>From Date</label>
</div>
<div class="col-lg-2">
<input type="Date" name="fromDate" id="fromDate" class="form-control form-control-sm"
placeholder="Client">
</div>
<div class="col-lg-1">
<label>To Date</label>
</div>
<div class="col-lg-2">
<input type="Date" name="toDate" id="toDate" class="form-control form-control-sm">
</div>
<div class="col-lg-1 mt-1" style="font-size: 14px; font-weight:bold;">
<label><input type="checkbox" name="All Date" id="allDates">&nbsp All Dates</label>
</div>
<div class="col-lg-1 mt-1">
<label>Support Limit</label>
</div>
<div class="col-lg-1">
<input type="text" name="supportLimit" id="supportLimit" class="form-control form-control-sm"
value="" readonly="">
</div>
<div class="col-lg-1 mt-1">
<label>Support Given</label>
</div>
<div class="col-lg-1">
<input type="text" name="supportgiven" id="supportgiven" class="form-control form-control-sm"
value="" readonly="">
</div>
</div>
</div>
</div>
<!-- //end card one -->
<div class="row">
<div class="col-lg-12">
<div class="block">
<div class="card-body p-0">
<div style="height:200px;overflow-y: auto;" class="outer">
<table id="tblServiceOrders" class="table table-striped table-sm table-hover table-bordered">
<thead class="bg-dark">
<tr class="font" style="color: white;">
<th>Order Date</th>
<th>Order By</th>
<th>Service Name</th>
<th>Cost</th>
<th>Support</th>
<th>Payable</th>
<th>Select</th>
</tr>
</thead>
<tbody id="tbody" class="rowClick">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="collapse" id="tblSupportDetailCollapse">
<div class="block">
<div class="card-body p-0">
<div style="height:100px;overflow-y: auto;" class="outer">
<table id="supportDetail" class="table table-striped table-sm table-hover table-bordered">
<thead class="bg-dark">
<tr class="font" style="color: white;">
<th>Order Date</th>
<th>Order By</th>
<th>Service Name</th>
<th>Cost</th>
<th>Support</th>
<th>Payable</th>
<th>Select</th>
</tr>
</thead>
<tbody id="tbody" class="rowClick">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- end second table -->
<!-- here is start final calculation of financial support -->
<div class="card">
<div class="card-body pb-2">
<div class="row">
<div class="col-lg-1">
<label>Total Amount</label>
</div>
<div class="col-lg-1">
<input type="text" name="totalAmount" id="totalAmount" class="form-control form-control-sm"
value="" readonly="">
</div>
<div class="col-lg-1">
<label>Support </label>
</div>
<div class="col-lg-1">
<input type="text" name="supportAmount" id="supportAmount"
class="form-control form-control-sm" value="" readonly="">
</div>
<div class="col-lg-1">
<label>Payable</label>
</div>
<div class="col-lg-1">
<input type="text" name="payableAmount" id="payableAmount"
class="form-control form-control-sm" value="" readonly="">
</div>
<div class="col-lg-2 mb-1">
<select class="form-control form-control-sm supportType" id="supportType">
<option value="SELECT">SELECT</option>
</select>
</div>
<div class="col-lg-1 mb-1">
<select class="form-control form-control-sm percentageSupport" id="percentageSupport">
<option value="SELECT">SELECT</option>
</select>
</div>
<div class="col-lg-1">
<input type="text" name="currentSupport" id="currentSupport"
class="form-control form-control-sm" value="" >
</div>
<div class="col-lg-1">
<label>Net Payable</label>
</div>
<div class="col-lg-1">
<input type="text" name="netPayable" id="netPayable" class="form-control form-control-sm"
value="" readonly="">
</div>
</div>
</div>
</div>
<!-- here calacualtion here -->
<div class="card mb-2">
<div class="card-body forms">
<div class="row">
<div class="col-lg-1 mb-1">
<label>Remarks</label>
</div>
<div class="col-lg-11 mb-1">
<input type="text" name="comments" id="comments" class="form-control form-control-sm">
</div>
</div> <!-- row end -->
</div> <!-- card body forms -->
</div> <!-- card mb-2 -->
<div class="block border">
<div class="card-body pt-2 pb-2">
<div class="row">
<div class="col-lg-2">
</div>
<div class="col-lg-2">
<a class="btn btn-sm btn-secondary col-lg-12" id="btnSaveFinanicialSupport" style="color:white">Financial Support</a>
</div>
<div class="col-lg-2">
<a class="btn btn-sm btn-outline-danger col-lg-12" id="">Cancel Support</a>
</div>
<div class="col-lg-2">
<a class="btn btn-sm btn-secondary col-lg-12" id="btngenerateinvoice"
style="color:white">Patient Support History</a>
</div>
<div class="col-lg-2">
<button class="btn btn-primary" id="supportDetail" type="button" data-toggle="collapse"
data-target="#tblSupportDetailCollapse" aria-expanded="false"
aria-controls="tblSupportDetailCollapse">
Support Detail
</button>
</div>
</div>
</div>
</div>
</form>
</div>
<link rel="stylesheet" href="{{ url('PublicCssForm/PacslinkCustomcss.min.css') }}">
<script src="{{ url('js/jquery.min.js') }}"></script>
<script src="{{ url('js/moment.min.js') }}"></script>
<script src="{{ url('theme/bootstrap.min.js') }}"></script>
<script src="{{ url('OrderInvoiceJs/FinancialSupport.min.js') }}"></script>
#endsection

As #aynber mentions in his comment to your question, you are not creating or saving a model, which is obviously the main problem here.
I see that you have this line:
$obj = new SessionClass(); which I assume is the model you want to save, but you do nothing with it, and you also overwrite it below your loop.
First of all, you need to have fields fillable on that model and then either save() or create() with data.
You can see an example of it here https://laravel.com/docs/9.x/eloquent#inserts
Simple example:
class Object extends Model
{
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = ['data1', 'data2', 'data3'];
}
You can then use this class to do something like:
$obj = new Object;
$object->save([
'data1' => 'some value',
'data2' => 'some value',
'data3' => 'some value',
])
// You can also do it like, which will create and save it for you.
$obj = Object::create([
'data1' => 'some value',
'data2' => 'some value',
'data3' => 'some value',
]);
If the fields are not described in the $fillable array of the model, they will not be persisted to the database.

Related

Table disappears after clicking on add button on Livewire

My Livewire Component
public $productId;
public $allTariff = [];
public $rowProducts = [];
public function mount()
{
$this->rowProducts = Products::all();
$this->allTariff = [
['productId' => '', 'basicCharge' => '', 'additionalCharge' => '']
];
}
public function addProduct()
{
$this->allTariff[] = ['productId' => '', 'basicCharge' => '', 'additionalCharge' => ''];
}
public function render()
{
$rowProducts = Products::all();
return view('livewire.admin.admin-add-tariffs-component', ['rowProducts'=>$rowProducts)->layout('layouts.admin.base');
}
My View File
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Add Tariff</h6>
</div>
<div class="card-body">
<form wire:submit.prevent="storeTariff">
#csrf
<div class="form-row">
<!-- Default input -->
<div class="form-group col-md-8">
<input type="text" class="form-control" placeholder="Enter Tariff Name" wire:model="tariffName" >
</div>
</div><hr>
<div class="card">
<div class="card-header">
<h6 class="text-primary">Products, Basic and Weight Charges</h6>
</div>
<div class="card-body">
<table class="table" id="products_table">
<thead>
<tr>
<th>Product</th>
<th>Basic Charge</th>
<th>Weight Charge</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach ($allTariff as $index => $value)
<tr>
<td>
<select name="allTariff[{{$index}}][productId]"
wire:model="allTariff.{{ $index }}.productId"
class="custom-select custom-select-sm form-control form-control-sm">
#foreach ($rowProducts as $product)
<option value="{{ $product->id }}">
{{ $product->product_name }}
</option>
#endforeach
</select>
</td>
<td>
<input type="text" class="form-control form-control-user" name="allTariff[{{$index}}][basicCharge]" placeholder="Basic Charge" wire:model="allTariff.{{ $index }}.basicCharge" required>
</td>
<td>
<input type="text" class="form-control form-control-user" name="allTariff[{{$index}}][additionalCharge]" placeholder="Weight Charge" wire:model="allTariff.{{ $index }}.additionalCharge" required>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-secondary"
wire:click.prevent="addProduct">+ Add Another Product</button>
</div>
</div>
</div>
</div>
<hr>
{{-- <div class="form-row">
<div class="form-group col-md-3"> --}}
<button type="submit" class="form-control btn btn-small btn-primary">Add
Tariff</button>
{{-- </div>
</div> --}}
</form>
</div>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
Every time I click on the add tariff button this photo it give the blank page on this photo, but on console an html response is given.
I have tried a couple methods and tricks still no way out, just stuck for days
I have already include the livewire #livewireStyles and #livewireScripts, and i can't find an answer anywhere else cause i don't see any question that match my problem, and i'm kinda new to livewire
When using Livewire, there are a few things you need to be aware of. Due to the nature of how Livewire updates the page, there are some structural rules you need to follow.
The first and probably most important thing here, is that every Livewire-component view should only consist of one root element. And this includes comments!
If we count the root elements in your view, there are three - a comment, a div, and then another comment. So the first thing I did here, was to move the comments inside that div.
<div class="container-fluid">
<!-- Begin Page Content -->
<!-- Page Heading -->
<div class="row">
<div class="col-lg-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Add Tariff</h6>
</div>
<div class="card-body">
<form wire:submit.prevent="storeTariff">
#csrf
<div class="form-row">
<!-- Default input -->
<div class="form-group col-md-8">
<input type="text" class="form-control" placeholder="Enter Tariff Name"
wire:model="tariffName">
</div>
</div>
<hr>
<div class="card">
<div class="card-header">
<h6 class="text-primary">Products, Basic and Weight Charges</h6>
</div>
<div class="card-body">
<table class="table" id="products_table">
<thead>
<tr>
<th>Product</th>
<th>Basic Charge</th>
<th>Weight Charge</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach ($allTariff as $index => $value)
<tr>
<td>
<select name="allTariff[{{ $index }}][productId]"
wire:model="allTariff.{{ $index }}.productId"
class="custom-select custom-select-sm form-control form-control-sm">
#foreach ($rowProducts as $product)
<option value="{{ $product->id }}">
{{ $product->product_name }}
</option>
#endforeach
</select>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][basicCharge]"
placeholder="Basic Charge"
wire:model="allTariff.{{ $index }}.basicCharge" required>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][additionalCharge]"
placeholder="Weight Charge"
wire:model="allTariff.{{ $index }}.additionalCharge"
required>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-secondary" wire:click.prevent="addProduct">+ Add Another Product</button>
</div>
</div>
</div>
</div>
<hr>
{{-- <div class="form-row">
<div class="form-group col-md-3"> --}}
<button type="submit" class="form-control btn btn-small btn-primary">Add
Tariff</button>
{{-- </div>
</div> --}}
</form>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
Then another thing I would recommend that you look into is using wire:key on the tr element inside your table-loop, and on the option element inside your inner loop. The value to wire:key should always be unique to that particular row, so using $loop->index is not generally advised. You can generate a dummy-ID for each record that you add to your array, which sole purpose is to track the individual row. Here's how, see the wire:key I added in the template,
<div class="container-fluid">
<!-- Begin Page Content -->
<!-- Page Heading -->
<div class="row">
<div class="col-lg-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Add Tariff</h6>
</div>
<div class="card-body">
<form wire:submit.prevent="storeTariff">
#csrf
<div class="form-row">
<!-- Default input -->
<div class="form-group col-md-8">
<input type="text" class="form-control" placeholder="Enter Tariff Name"
wire:model="tariffName">
</div>
</div>
<hr>
<div class="card">
<div class="card-header">
<h6 class="text-primary">Products, Basic and Weight Charges</h6>
</div>
<div class="card-body">
<table class="table" id="products_table">
<thead>
<tr>
<th>Product</th>
<th>Basic Charge</th>
<th>Weight Charge</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach ($allTariff as $index => $value)
<tr wire:key="tariff-{{ $value->wireKey }}">
<td>
<select name="allTariff[{{ $index }}][productId]"
wire:model="allTariff.{{ $index }}.productId"
class="custom-select custom-select-sm form-control form-control-sm">
#foreach ($rowProducts as $product)
<option value="{{ $product->id }}" wire:key="product-{{ $product->id }}">
{{ $product->product_name }}
</option>
#endforeach
</select>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][basicCharge]"
placeholder="Basic Charge"
wire:model="allTariff.{{ $index }}.basicCharge" required>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][additionalCharge]"
placeholder="Weight Charge"
wire:model="allTariff.{{ $index }}.additionalCharge"
required>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-secondary" wire:click.prevent="addProduct">+ Add Another Product</button>
</div>
</div>
</div>
</div>
<hr>
{{-- <div class="form-row">
<div class="form-group col-md-3"> --}}
<button type="submit" class="form-control btn btn-small btn-primary">Add
Tariff</button>
{{-- </div>
</div> --}}
</form>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
And then in your component, just generate a unique string
class AdminAddTariffsComponent
{
public $productId;
public $allTariff = [];
public $rowProducts = [];
public function mount()
{
$this->rowProducts = Products::all();
$this->addProduct();
}
public function addProduct()
{
$this->allTariff[] = [
'productId' => '',
'basicCharge' => '',
'additionalCharge' => '',
'wireKey' => \Str::uuid(),
];
}
public function render()
{
return view('livewire.admin.admin-add-tariffs-component')
->layout('layouts.admin.base');
}
}

I'm handling Client site from admin panel

i have created the admin panel where im saving every data, the main thing is the user want to add or edit data from admin panel for his site. its like a blog.
first i have done the slider section where im fetching data from admin panel to client site.
this is the slider section code which is working perfectly.
Add file
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ARABIC SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Manage Home Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/list')}}">Back</a>
</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="tab-content p-0">
<form action="{{ url('/arabicpost/submit')}}" method="POST" enctype="multipart/form-data">
#csrf
<div class="card-body">
<div class="form-group">
<label for="">Title 1</label>
<input type="text" name="title" class="form-control" id="exampleInputTitle" placeholder="Enter Title 1">
#error('title')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description 1</label>
<textarea class="form-control" name="description" id="" cols="30" rows="10" placeholder="Description 1"></textarea>
#error('description')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input 1</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12">
Second Banner
</h3>
</div>
<div class="card-body">
<div class="form-group">
<label for="">Title 2</label>
<input type="text" name="title2" class="form-control" id="exampleInputTitle" placeholder="Enter Title 2">
#error('title2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description 2</label>
<textarea class="form-control" name="description2" id="" cols="30" rows="10" placeholder="Description 2"></textarea>
#error('description2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input 2</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image2" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image2')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div><!-- /.card-body -->
</div></div></div></div>
#endsection
List File
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<div class="card" style="margin-top:5%">
<div class="card-header">
<h2 class="text-center">English Home Section</h2>
<div class="col-sm-12" style="text-align: center; color:green; font-size:20px">{{session('msg')}}</div>
<div class="col-sm-12" style="text-align: center; color:red; font-size:20px">{{session('msgForDelete')}}</div>
</div>
<div class="card-header">
<a class="btn btn-success" href="{{ URL('/admin/post/add')}}">Add Post</a>
</div>
<!-- /.card-header -->
<div class="card-body">
<table id="example1" class="table table-bordered table-striped table-responsive">
<thead>
<tr width="100%">
<th width="3%">ID</th>
<th width="10%">Title 1</th>
<th width="23.5%">Description 1</th>
<th width="10%">Title 2</th>
<th width="23.5%">Description 2</th>
<th width="10%">Image 1</th>
<th width="10%">Image 2</th>
<th width="10%">Action</th>
</tr>
</thead>
<tbody>
<?php
// echo '<pre>';
// print_r([$result]);
// die();
?>
#foreach ($result as $list)
<tr>
<td>{{$list->id}}</td>
<td>{{$list->title}}</td>
<td>{{$list->description}}</td>
<td>{{$list->title2}}</td>
<td>{{$list->description2}}</td>
<td><img src="{{ asset('storage/app/public/post/'.$list->image) }}" width="150px"/></td> <td><img src="{{ asset('storage/app/public/post/secondbanner/'.$list->image2) }}" width="150px"/></td>
<td><a class="btn btn-primary" href="{{('/haffiz/admin/post/edit/'.$list->id)}}">Edit</a>
<a class="btn btn-danger" href="{{('/haffiz/admin/post/delete/'.$list->id)}}">Delete</a>
</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Title 1</th>
<th>Description 1</th>
<th>Title 2</th>
<th>Description 2</th>
<th>Image 1</th>
<th>Image 2</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div></div></div> </div>
#endsection
edit file
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ENGLISH SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Manage Home Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/list')}}">Back</a>
</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="tab-content p-0">
<form action="{{ url('/admin/post/update/'.$result['0']->id)}}" method="POST" enctype="multipart/form-data">
#csrf
<div class="card-body">
<div class="form-group">
<label for="">Title</label>
<input type="text" name="title" class="form-control" id="exampleInputTitle" value="{{$result['0']->title}}" placeholder="Enter Title">
#error('title')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description</label>
<textarea class="form-control" name="description" id="" cols="30" rows="10" placeholder="Description">{{$result['0']->description}} </textarea>
#error('description')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-body">
<div class="form-group">
<label for="">Title 2</label>
<input type="text" name="title2" class="form-control" id="exampleInputTitle" value="{{$result['0']->title2}}" placeholder="Enter Title">
#error('title2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description 2</label>
<textarea class="form-control" name="description2" id="" cols="30" rows="10" placeholder="Description">{{$result['0']->description2}} </textarea>
#error('description2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input 2</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image2" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image2')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div><!-- /.card-body -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ENGLISH SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Manage Home Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/list')}}">Back</a>
</h3>
</div>
</div>
</div>
</div>
</div>
#endsection
its Controller(Post)
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Post extends Controller
{
function listing()
{
$data['result'] = DB::table('posts')->orderBy('id','desc')->get();
return view('admin.post.list',$data);
}
function submit(Request $req)
{
//validation
$req->validate([
'title' => 'required',
'description' => 'required',
'title2' => 'required',
'description2' => 'required',
'image' => 'mimes: jpg,jpeg,png',
'image2' => 'mimes: jpg,jpeg,png'
]);
//storing image
$image=$req->file('image');
$ext = $image->extension();
$file=time().'.'.$ext;
$image->storeAs('public/post',$file);
$image2=$req->file('image2');
$ext2 = $image2->extension();
$file2=time().'.'.$ext2;
$image2->storeAs('public/post/secondbanner',$file2);
//array
$data = array(
'title' => $req->input('title'),
'description' => $req->input('description'),
'title2' => $req->input('title2'),
'description2' => $req->input('description2'),
'image' => $file,
'image2' => $file2,
);
//inserting data
DB::table('posts')->insert($data);
$req->session()->flash('msg','Data has been Added');
return redirect('/admin/post/list');
}
function delete(Request $req , $id)
{
DB::table('posts')->where('id',$id)->delete();
$req->session()->flash('msgForDelete','Data has been Deleted');
return redirect('/admin/post/list');
}
function edit(Request $req , $id)
{
$data['result'] = DB::table('posts')->where('id',$id)->get();
return view('admin.post.edit',$data);
}
function update(Request $req , $id)
{
//validation
$req->validate([
'title' => 'required',
'description' => 'required',
'title2' => 'required',
'description2' => 'required',
'image' => 'mimes: jpg,jpeg,png',
'image2' => 'mimes: jpg,jpeg,png'
]);
//array
$data = array(
'title' => $req->input('title'),
'description' => $req->input('description'),
'title2' => $req->input('title2'),
'description2' => $req->input('description2'),
);
if($req->hasfile('image'))
{
$image=$req->file('image');
$ext = $image->extension();
$file=time().'.'.$ext;
$file2=time().'.'.$ext;
$image->storeAs('public/post/',$file,$file2);
$data['image']=$file;
}
if($req->hasfile('image2'))
{
$image2=$req->file('image2');
$ext = $image2->extension();
$file2=time().'.'.$ext;
$image2->storeAs('public/post/secondbanner',$file2);
$data['image2']=$file2;
}
//updating data
DB::table('posts')->where('id',$id)->update($data);
$req->session()->flash('msg','Data has been Updated');
return redirect('/admin/post/list');
}
}
and this is a controller where im sending data to client site.
<?php
namespace App\Http\Controllers\user;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class EngHafizController extends Controller
{
public function login()
{
return view('user.english.login');
}
public function registration()
{
return view('user.english.registration');
}
public function homefront()
{
return view('user.english.index');
}
public function home()
{
$data['result'] = DB::table('posts')->get();
return view('user.english.index',$data);
}
public function about()
{
$data['aboutresult'] = DB::table('abouts')->get();
return view('user.english.about',$data);
}
public function whyhaffez()
{
return view('user.english.whyhaffez');
}
public function oursheikh()
{
return view('user.english.oursheikh');
}
public function contact()
{
return view('user.english.contact');
}
}
This is all working properly.
lets get to the point. when try to do the same for ABOUT section
it give me the error which is
(Undefined variable: aboutresult (View:C:\xampp\htdocs\haffiz\resources\views\user\english\index.blade.php))
i do the same thing for about section
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class AboutController extends Controller
{
function about_listing()
{
$data['aboutresult'] = DB::table('abouts')->orderBy('id','desc')->get();
return view('admin.post.about.aboutlist',$data);
}
function about_submit(Request $request)
{
//validation
$request->validate([
'title3' => 'required',
'heading3' => 'required',
'description3' => 'required',
'image3' => 'mimes: jpg,jpeg,png'
]);
//storing image
$image3=$request->file('image3');
$ext = $image3->extension();
$file=time().'.'.$ext;
$image3->storeAs('public/post/about_image',$file);
//array
$data = array(
'title3' => $request->input('title3'),
'heading3' => $request->input('heading3'),
'description3' => $request->input('description3'),
'image3' => $file,
);
//inserting data
DB::table('abouts')->insert($data);
$request->session()->flash('msg','Data has been Added');
return redirect('/admin/post/about/aboutlist');
}
function about_delete(Request $request , $id)
{
DB::table('abouts')->where('id',$id)->delete();
$request->session()->flash('msgForDelete','Data has been Deleted');
return redirect('/admin/post/list');
}
function about_edit(Request $request , $id)
{
$data['aboutresult'] = DB::table('abouts')->where('id',$id)->get();
return view('admin.post.about.aboutedit',$data);
}
function about_update(Request $request , $id)
{
//validation
$request->validate([
'title3' => 'required',
'heading3' => 'required',
'description3' => 'required',
'image3' => 'mimes: jpg,jpeg,png'
]);
//array
$data = array(
'title3' => $request->input('title3'),
'heading3' => $request->input('heading3'),
'description3' => $request->input('description3'),
);
if($request->hasfile('image3'))
{
$image3=$request->file('image3');
$ext = $image3->extension();
$file=time().'.'.$ext;
$image3->storeAs('public/post/about_image',$file);
$data['image3']=$file;
}
//updating data
DB::table('abouts')->where('id',$id)->update($data);
$request->session()->flash('msg','Data has been Updated');
return redirect('/admin/post/about/aboutlist');
}
}
aboutLIST
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<div class="card">
<div class="card-header">
<h2 >About Section</h2>
<div class="col-sm-12" style="text-align: center; color:green; font-size:20px">{{session('msg')}}</div>
<div class="col-sm-12" style="text-align: center; color:red; font-size:20px">{{session('msgForDelete')}}</div>
</div>
<div class="card-header">
<a class="btn btn-success" href="{{ URL('/admin/post/about/about')}}">Add Post</a>
</div>
<!-- /.card-header -->
<div class="card-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr width="100%">
<th width="">ID</th>
<th width="10">Title </th>
<th width="40">Heading</th>
<th width="15">Description </th>
<th width="10">Image </th>
<th width="25%">Action</th>
</tr>
</thead>
<tbody>
<?php
// echo '<pre>';
// print_r([$aboutresult]);
// die();
?>
#foreach ($aboutresult as $aboutlist)
<tr>
<td>{{$aboutlist->id}}</td>
<td>{{$aboutlist->title3}}</td>
<td>{{$aboutlist->heading3}}</td>
<td>{{$aboutlist->description3}}</td>
<td><img src="{{ asset('storage/app/public/post/about_image/'.$aboutlist->image3) }}" width="150px" height="100px"/></td>
<td>
<a class="btn btn-primary" href="{{('/haffiz/admin/post/about/aboutedit/'.$aboutlist->id)}}">Edit</a>
<a class="btn btn-danger" href="{{('/haffiz/admin/post/delete'.$aboutlist->id)}}" >Delete</a>
</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr>
<th width="4">ID</th>
<th width="10">Title </th>
<th width="40">Heading</th>
<th width="15">Description </th>
<th width="10">Image</th>
<th width="25%">Action</th>
</tr>
</tfoot>
</table>
</div>
<!-- /.card-body -->
</div>
</div>
</div>
#endsection
aboutedit
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ENGLISH SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Edit About Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/about/aboutlist')}}">Back</a>
</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="tab-content p-0">
<form action="{{ url('/admin/post/about/update/'.$aboutresult['0']->id)}}" method="POST" enctype="multipart/form-data">
#csrf
<div class="card-body">
<div class="form-group">
<label for="">Title</label>
<input type="text" name="title3" class="form-control" id="exampleInputTitle" value="{{$aboutresult['0']->title3}}" placeholder="Enter Title">
#error('title3')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Heading</label>
<input class="form-control" name="heading3" id="" placeholder="Heading" value="{{$aboutresult['0']->heading3}}">
#error('heading3')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description </label>
<textarea class="form-control" name="description3" id="" cols="30" rows="10" placeholder="Description ">{{$aboutresult['0']->description3}}</textarea>
#error('description3')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image3" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image3')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div><!-- /.card-body -->
</div>
</div>
</div>
</div>
#endsection
this the index file where im fetching
#foreach ($result as $list)
<img src="{{ asset('storage/app/public/post/'.$list->image) }}" class="d-block w-100" alt="...">
<div class="col-12 text-left">
<h1 class="animated slideInDown">{{ $list->title }}</h1>
<svg class="animated slideInDown" width="128" height="9" viewBox="0 0 128 9" fill="none" xmlns="http://www.w3.org/2000/svg">
</svg>
<p class="animated slideInLeft">{{ $list->description }}</p>
Read More
</div>
<div class="carousel-item">
<img src="{{ asset('storage/app/public/post/secondbanner/'.$list->image2) }}" class="d-block w-100" alt="...">
<h1 class="animated slideInDown">{{ $list->title2}}</h1>
<p class="animated slideInLeft">{{ $list->description2 }}</p>
#endforeach
</div>
about section
#foreach($aboutresult as $aboutlist)
<div class="col-xl-7 about-p">
<h5 class="about-welcome">{{$aboutlist->title3}}</h5>
#endforeach
public function home()
{
$data['aboutresult'] = DB::table('abouts')->get();
$data['result'] = DB::table('posts')->get();
return view('user.english.index',$data);
}

base table or view not found?

when i enter question and click on add button i show error base table not found i cant understand what is issue and its solution so if any one know help me...i waste lot of time on it am begninner so difficult to identify error...
web.php
Route::post('/admin/add_new_question','Admin#add_new_question');
AdminController
public function add_new_question(Request $request)
{
$validator=Validator::make($request->all(),['question'=>'required','option1'=>'required','option2'=>'required','option3'=>'required','option4'=>'required','ans'=>'required']);
if($validator->passes())
{
$question = new Oex_exam_question_master();
$question->exam_id=$request->exam_id;
$question->question=$request->question;
$question->ans=$request->ans;
$question->options=json_encode(array('option1'=>$request->option1,'option2'=>$request->option2,'option3'=>$request->option3,'option4'=>$request->option4));
$question->save();
$arr=array('status'=>'true','message'=>'Question Successfully Added','reload'=>url('admin/add_question/'.$request->exam_id));
}
else{
$arr=array('status'=>'false','message'=>$validator->errors()->all());
}
echo json_encode($arr);
}
add_question.blade.php
#extends('layouts.app')
#section('title','Exam Question')
#section('content')
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">Exam Question</h1>
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item active">Exam Question</li>
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<!-- Default box -->
<div class="card">
<div class="card-header">
<div class="card-tools">
<a class="btn btn-info btn-sm" href="javascript:;" data-toggle="modal" data-target="#myModal">Add New</a>
</div>
</div>
<div class="card-body">
<table class="table table-striped table-bordered table-hover datatable">
<thead>
<tr>
<th>#</th>
<th>Question</th>
<th>Ans</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>#</th>
<th>Question</th>
<th>Ans</th>
<th>Status</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
<!-- /.card-body -->
<!-- /.card-footer-->
</div>
<!-- /.card -->
</div>
</div>
</div>
</section>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add New Exam</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form action="{{ url('admin/add_new_question') }} " class="database_operation">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label>Enter Question</label>
{{ csrf_field() }}
<input type="hidden" name="exam_id" value="{{ Request::segment(3) }}">
<input type="text" name="question" required="required" placeholder="Enter Question" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Select Option 1</label>
<input type="text" required="required" name="option1" placeholder="Enter Option 1" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Select Option 2</label>
<input type="text" required="required" name="option2" placeholder="Enter Option 2" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Select Option 3</label>
<input type="text" required="required" name="option3" placeholder="Enter Option 3" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Select Option 4</label>
<input type="text" required="required" name="option4" placeholder="Enter Option 4" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label>Enter Right Ans</label>
<input type="text" required="required" name="ans" placeholder="Enter Right Ans" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<button class="btn btn-primary"> Add</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
Table oex_exam_question_master
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateOexExamQuestionMastersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('oex_exam_question_masters', function (Blueprint $table) {
$table->increments('id');
$table->string('exam_id')->nullable();
$table->string('question')->nullable();
$table->string('ans')->nullable();
$table->string('options')->nullable();
$table->string('status')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('oex_exam_question_masters');
}
}
Error
{
"message": "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'my_pro_online_ex.oex_exam_question_master' doesn't exist (SQL: insert into `oex_exam_question_master` (`exam_id`, `question`, `ans`, `options`, `updated_at`, `created_at`) values (4, Question 2, D, {\"option1\":\"A\",\"option2\":\"B\",\"option3\":\"C\",\"option4\":\"D\"}, 2020-07-21 07:32:03, 2020-07-21 07:32:03))",
"exception": "Illuminate\\Database\\QueryException",
"file": "C:\\xampp\\htdocs\\project\\online_exm_sys\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php",
"line": 664,
"trace": [
{
"file": "C:\\xampp\\htdocs\\project\\online_exm_sys\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php",
"line": 624,
"function": "runQueryCallback",
"class": "Illuminate\\Database\\Connection",
"type": "->"
You need to assign a table name in your model.
class Oex_exam_question_master extends Model
{
protected $table = 'oex_exam_question_masters';
}

The GET method is not supported for this route. Supported methods: POST When Insert data

I just tried to insert data using ajax json but I'm getting a error like this. I checked in the controller, route and model. There's nothing wrong with how to set it up. Please help.
For View Blade
function add() {
save_method = 'add';
$('#form_jabatan')[0].reset(); // reset form on modals
$('#modal_form').modal('show'); // show bootstrap modal
$('[name="kode"]').prop("readonly", false);
}
function save() {
var url = "";
if (save_method === 'add') {
url = "<?php echo url('/simpanjabatan') ?>";
} else {
url = "<?php echo url('/simpanjabatan') ?>";
}
$.ajax({
url: url,
type: "POST",
data: $('#form_jabatan').serialize(),
dataType: "JSON",
success: function (data) {
if (data.errors) {
jQuery.each(data.errors, function (key, value) {
jQuery('.alert-danger').show();
jQuery('.alert-danger').append('<p>' + value + '</p>');
});
} else {
alert(data.status);
$('#modal_form').modal('hide');
reloadpage();
}
},
error: function (request, status, error) {
alert("Error json " + error);
json = $.parseJSON(request.responseText);
$.each(json.errors, function (key, value) {
$('.alert-danger').show("");
$('.alert-danger').append('<p>' + value + '</p>');
});
}
});
}
</script>
<!-- Page Content -->
<div class="content">
<h2 class="content-heading">Form Detail Jabatan</h2>
<!-- Dynamic Table Full -->
<div class="block">
<div class="block-header block-header-default">
<h3 class="block-title">DATA TABLE Detail Jabatan</h3>
</div>
<div class=" block-content block-content-full table-responsive">
<button type="button" onclick="add();" class="btn btn-primary mr-5 mb-5" data-toggle="modal">
<i class="fa fa-plus mr-5"></i>Kelola Jabatan
</button>
<div class="table-responsive">
<table id="example" class=" table table-striped js-dataTable-full-pagination ">
<thead>
<tr>
<th >ID JABATAN</th>
<th >JENIS JABATAN</th>
<th >GAJI_POKOK</th>
<th >Aksi</th>
</thead>
<tbody>
</tbody>
</table>
</div>
<!-- DataTables functionality is initialized with .js-dataTable-full-pagination class in js/pages/be_tables_datatables.min.js which was auto compiled from _es6/pages/be_tables_datatables.js -->
</div>
</div>
</div>
<!-- END Page Content -->
<!-- From Right Modal -->
<div class="modal fade" id="modal_form" tabindex="-1" role="dialog" aria-labelledby="modal-fromright"
aria-hidden="true">
<div class="modal-dialog modal-dialog-fromright" role="document">
<div class="modal-content">
<div class="block block-themed block-transparent">
<div class="block-header bg-primary-dark">
<h3 class="block-title">FORM Detail Jabatan</h3>
<div class="block-options">
<button type="button" class="btn-block-option" data-dismiss="modal" aria-label="Close">
<i class="si si-close"></i>
</button>
</div>
</div>
<div class="modal-body form">
<form action="#" id="form_jabatan" class="form-horizontal">
<input name="_token" type="hidden" id="_token" value="{{ csrf_token() }}"/>
<div class="form-body">
<div class="form-group">
{{--<label type="hidden" class="control-label col-md-3">Kode</label>--}}
<div class="col-md-9">
<input name="kode" type="hidden" class="form-control" type="text"
placeholder="Kode">
</div>
</div>
<div class="form-group row">
<label class="col-md-3 col-form-label" for="val-name">Jenis Jabatan</label>
<div class="col-md-9">
<select class="form-control" id="jabatan" name="jabatan">
<option value="0">Silahkan Pilih</option>
<option value="1">Ka Mantri</option>
<option value="1">Ka Mantri(baru)</option>
<option value="2">Kasir</option>
<option value="2">Staff Admin</option>
<option value="2">Mantri</option>
<option value="2">Mantri(Baru)</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-md-3 col-form-label" for="val-name">Gaji Pokok</label>
<div class="col-md-9">
<input type="text" class="form-control" id="gaji" name="gaji"
placeholder="Masukan gaji...">
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" id="btnSave" onclick="save();" class="btn btn-primary">Save
</button>
</div>
</div>
</div>
</div>
</div>
<!-- END From Right Modal -->
For Controller
public function simpanjabatan(Request $req)
{
$obj = new DetailJabatanModel();
$obj->id_jabatan = $req->input('kode');
$obj->jabatan = $req->input('jabatan');
$obj->gaji_pokok = $req->input('gaji');
$simpan = $obj->save();
if ($simpan == 1) {
$status = "Tersmpan";
} else {
$status = "Gagal";
}
echo json_encode(array("status" => $status));
}
for route
Route::post('/simpanjabatan', 'FormJabatanController#simpanjabatan');
I want to insert with json but I got erorr:
The GET method is not supported for this route. Supported methods: POST.

Form with checkboxes pass to ajax

I'm using Laravel 4 on this. I have a form with a list of departments in which there are members per department. I used an accordion to place all members under one checkbox of department. Now when I check the checkbox and submit it I want it to be posted on my ajax.
Here's what I can do but found an error.
Syntax error, unrecognized expression: input[name=dept_id:checked
HTML
<div class="col-md-6 col-sm-6">
<div class="blue-steel box portlet">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-calendar"></i>Bulk select Department off day
</div>
</div><!-- /.portlet-title -->
<div class="portlet-body form">
<div class="form-body">
{{Form::open(['url'=>url('admin/schedule'), 'id' => 'department_bulk_off_day', 'class'=>'form-horizontal', 'method'=>'GET'])}}
<div class="form-group">
<label class="col-md-3 control-label" style="padding-left: 0px;">Select Department</label>
<div class="col-md-9">
<!-- <div id="accordion">
<h3><span id="id"><input type="checkbox"/></span>Text More text </h3>
<div>content etc</div>
</div> -->
<div class="employee_checkbox_wrapper" id="accordion">
<?php $department = DB::table('department')->get(); ?>
#foreach($department as $key => $val)
<label><span id="id"><input type="checkbox" name="dept_id[]" value="{{ $val->id }}"/></span>{{ $val->deptName }} </label>
<div>
<?php
$dept_id = $val->id;
$schedule = '';
$desig_ids = DB::table('designation')->where('deptID', $dept_id)->get();
foreach ($desig_ids as $desig_id) {
$emp_des = $desig_id->id;
$employee_desigs = DB::table('employees')->where('designation', $emp_des)->get();
foreach ($employee_desigs as $employee_desig) {
?>
<label style="margin-left: 15px;"><!-- <input type="checkbox" name="employee_id[]" value="{{ $employee_desig->id }}"/> -->
{{ $employee_desig->fullName }}
</label>
<a data-toggle="modal" data-id="{{ $employee_desig->id }}" data-target="#myModal" title="Add this item" class="open-AddBookDialog btn " href="#addBookDialog">
Change Department
</a>
</br>
<?php
}
}
?>
</div>
#endforeach
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" style="margin-top: 20px;">Select Date</label>
<div class="col-md-3">
<div class="input-group input-medium date date-picker" data-date-format="dd-mm-yyyy" data-date-viewmode="years" style="margin-top: 20px;">
<input type="text" class="form-control" name="off_day" value="{{ date('d-m-Y') }}">
<span class="input-group-btn">
<button class="btn default" type="button"><i class="fa fa-calendar"></i></button>
</span>
</div>
</div>
</div>
<div class="row form-group">
<div class="col-md-12 text-center">
{{Form::token()}}
<input type="hidden" name="department_bulk_off_day" value="2">
<button class="btn btn-button button-tip-form-submit">Update</button>
</div><!-- /.col-md-12 text-center -->
</div>
</form><!-- /.form-horizontal -->
</div><!-- /.form-body -->
{{ Form::close() }}
</div><!-- /.portlet-body form -->
</div><!-- /.blue-steel box portlet -->
</div><!-- /.col-md-6 col-sm-6 -->
And here's my JS
<script>
$('#department_bulk_off_day').on('submit', function(e){
e.preventDefault();
var checkValues = jQuery('input[name=dept_id:checked').map(function()
{
return $(this).val();
}).get();
alert(checkValues);
</script>
you can try the following code
var checkValues = jQuery('input[name="dept_id"]').map(function()
{
var this_var = $(this);
if($(this):checked){
return this_var.val();
}
}).get();
Try This. You have the selectors all messed up.
$('#department_bulk_off_day').on('submit', function(e){
e.preventDefault();
var checkValues = $('input[name="dept_id"]:checked').map(function()
{
return $(this).val();
}).get();
alert(checkValues);

Categories