I have a problem with my app , when i click the edit btn in the table then my modal is showed with data and when i click the second row in the table then my modal is not show.
this my controller :
public function edit_kpi_program_plan(Request $request)
{
$data = kpi_input_program::where('id' , $request->id)->first();
return response()->json($data, 200);
}
this my route :
Route::post('/edit-program-input', [InputController::class, 'edit_kpi_program_plan'])->name('edit.program');
this my button in blade:
Edit
this my modal in blade:
<!-- Modal Input Program Plan Value Update -->
<div class="modal fade" id="new_modal_plan" tabIndex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Input Program Plan</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{ route('update-kpi-program-plan') }}" method="post">
#csrf
<div class="form-group">
<label for="exampleFormControlSelect1">Pilih Item</label>
<select name="id_program_plan_update" class="form-control" id="exampleFormControlSelect1">
#forelse ($data_drop_update as $item)
<option value="{{ $item->id }}">{{ $item->program }}</option>
#empty
<td colspan="18"><h3 class="text-center">No Data Inputed</h3></td>
#endforelse
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Konfirmasi Pilihan</label>
<select name="kpi_program_plan_id" class="form-control" id="exampleFormControlSelect1">
#forelse ($data_drop as $item)
<option value="{{ $item->id }}">{{ $item->program }}</option>
#empty
<td colspan="18"><h3 class="text-center">No Data Inputed</h3></td>
#endforelse
</select>
</div>
<div class="form-group">
<table class="table table-bordered">
<thead>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
<th>Sep</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
</thead>
<tbody>
#foreach ($dataf as $item)
<td><input type="text" name="jan_plan" id="jan_plan" style="max-width: 40px"></td>
<td><input type="text" name="feb_plan" id="feb_plan" style="max-width: 40px"></td>
<td><input type="text" name="mar_plan" id="mar_plan" style="max-width: 40px"></td>
<td><input type="text" name="apr_plan" id="apr_plan" style="max-width: 40px"></td>
<td><input type="text" name="may_plan" id="may_plan" style="max-width: 40px"></td>
<td><input type="text" name="jun_plan" id="jun_plan" style="max-width: 40px"></td>
<td><input type="text" name="jul_plan" id="jul_plan" style="max-width: 40px"></td>
<td><input type="text" name="aug_plan" id="aug_plan" style="max-width: 40px"></td>
<td><input type="text" name="sep_plan" id="sep_plan" style="max-width: 40px"></td>
<td><input type="text" name="oct_plan" id="oct_plan" style="max-width: 40px"></td>
<td><input type="text" name="nov_plan" id="nov_plan" style="max-width: 40px"></td>
<td><input type="text" name="dec_plan" id="dec_plan" style="max-width: 40px"></td>
#endforeach
</tbody>
</table>
</div>
<button class="btn btn-primary" type="submit" id="btn-save">Save</button>
</form>
</div>
</div>
</div>
</div>
and this my ajax :
<script>
$(document).ready(function($) {
$('#btn-edit-plan').on('click', function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var id = $(this).data('id');
console.log(id);
// ajax
$.ajax({
type: "POST",
url: "{{ url('edit-program-input') }}",
data: { id: id },
dataType: 'json',
success: function(res) {
$('#new_modal_plan').modal('show');
$('#jan_plan').val(res.jan);
$('#feb_plan').val(res.feb);
$('#mar_plan').val(res.mar);
$('#apr_plan').val(res.apr);
$('#may_plan').val(res.may);
$('#jun_plan').val(res.jun);
$('#jul_plan').val(res.jul);
$('#aug_plan').val(res.aug);
$('#sep_plan').val(res.sep);
$('#oct_plan').val(res.oct);
$('#nov_plan').val(res.nov);
$('#dec_plan').val(res.dec);
}
});
});
})
</script>
The id attribute should be unique for every element in the page. but it is not like this with class attribute.
so update your button:
Edit
and update your jQuery selector to:
$(document).on('click', '.btn-edit-plan', function() {
// Your code here
})
You can learn more about it here: Difference between class and id in jQuery
Related
I'm beginner in Laravel. I'm using ajax. I want to display data of students (eleves) in my select option by first name (prénom) last name (nom), but the problem that it displays only the first name (prénom) without the last name (nom). However I need to associate first name and last name. Please help me.
Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Note;
use App\Matiere;
use App\Eleve;
use App\Classe;
use DB;
class DropdownlistController extends Controller
{
public function index()
{
$notes = Note::all();
$matieres = Matiere::all();
$eleves = Eleve::all();
$classes = Classe::all();
$classes = DB::table("classes")->pluck("classe","id");
return view('admin.dropdownlists',compact('classes','notes','matieres','eleves'));
}
public function store(Request $request)
{
Note::create($request->all());
return redirect()->back();
}
public function getStateList(Request $request)
{
$eleves = DB::table("eleves")
->where("classe_id",$request->classe_id)
->pluck("nom" ,"prenom","id");
return response()->json($eleves);
}
public function getCityList(Request $request)
{
$matieres = DB::table("matieres")
->where("classe_id",$request->classe_id)
->pluck("nom_matiere","id");
return response()->json($matieres);
}
}
My view there I'm using my function ajax
#extends('layouts.admin')
#section('content')
<section class="wrapper">
<div class="table-title">
<div class="row">
<div class="col-sm-6">
<h2> ESpace de Gestion <b></b> des notes </h2>
</div>
<div class="col-sm-6">
<a href="#addEmployeeModal" class=" btn btn-success" data-toggle="modal"><i class="material-icons"></i>
<span>Ajouter un nouvelle note </span></a>
</div>
</div>
</div>
<div class="row mt">
#if(session()->has('success'))
<div class="alert alert-success">
{{session()->get('success')}}
</div>
#endif
<div class="col-lg-12">
<div class="content-panel">
<section id="no-more-tables">
<table class="table table-bordered table-striped table-condensed cf">
<thead class="cf">
<tr>
<th>id-note</th>
<th>Nom</th>
<th>classe</th>
<th>matiére</th>
<th>Note</th>
<th>les actions</th>
</tr>
</thead>
<tbody>
#foreach($notes as $note)
<tr>
<td class="numeric" data-title="id-parent">{{$note->id}}</td>
<td class="numeric"
data-title="id-parent">{{$note->eleve->nom}} {{$note->eleve->prenom}}</td>
<td class="numeric" data-title="id-parent">{{$note->classe->classe}}</td>
<td class="numeric" data-title="id-parent">{{$note->matiere->nom_matiere}}</td>
<td class="numeric" data-title="Login">{{$note->note}}</td>
<td>
<button href="#editEmployeeModal" class="btn btn-theme"
data-target="#editEmployeeModal " data-catid={{$note->id}} class="edit"
data-toggle="modal"><i class="material-icons" data-toggle="tooltip"
title="Edit"></i></button>
<button href="#deleteEmployeeModal" class="btn btn-theme"
data-target="#deleteEmployeeModal" data-catid="{{$note->id}}"
class="delete" data-toggle="modal"><i class="material-icons"
data-toggle="tooltip"
title="Delete"></i>
</button>
</td>
</tr>
</tbody>
#endforeach
</table>
<div class="text-center">
</div>
<div class="clearfix">
<div class="hint-text">Affichage de <b>5</b> sur <b>25</b> entrées</div>
<div id="addEmployeeModal" href="create" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<form action="{{route('dropdownlists.store')}}" method="post">
{{csrf_field()}}
<div class="modal-header">
<h4 class="modal-title">Ajouter un éléve</h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×
</button>
</div>
<div class="modal-body">
<div class="panel-body">
<div class="form-group">
<label for="title">Select classe:</label>
<select id="classe" name="classe" class="form-control"
style="width:350px">
<option value="" selected disabled>Select</option>
#foreach($classes as $key => $classe)
<option value="{{$key}}"> {{$classe}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="title">Select classe:</label>
<select id="eleve" name="eleve" class="form-control"
style="width:350px">
</select>
</div>
<div class="form-group">
<label for="title">Select matiere:</label>
<select id="matiere" name="matiere" class="form-control"
style="width:350px">
<option value="" selected disabled>Select</option>
</select>
</div>
<div class="form-group">
<label>la note </label>
<input type="text" id="note" name="note" class="form-control"
required>
</div>
</div>
<div class="modal-footer">
<input type="button" class="btn btn-default" data-dismiss="modal"
value="Annuler">
<input type="submit" class="btn btn-success" value="Ajouter">
</div>
</form>
</div>
</div>
</div>
</div>
#endsection
#section('js')
<script type="text/javascript">
$('#classe').change(function () {
var classeID = $(this).val();
if (classeID) {
$.ajax({
type: "GET",
url: "{{url('get-state-list')}}?classe_id=" + classeID,
success: function (res) {
if (res) {
$("#eleve").empty();
$("#eleve").append('<option>Select</option>');
$.each(res, function (key, value) {
$("#eleve").append('<option
value = "'+eleve.age+'" > '+value+' < /option>');
});
} else {
$("#eleve").empty();
}
}
});
} else {
$("#classe").empty();
$("#matiere").empty();
}
});
$('#classe').on('change', function () {
var classeID = $(this).val();
if (classeID) {
$.ajax({
type: "GET",
url: "{{url('get-city-list')}}?classe_id=" + classeID,
success: function (res) {
if (res) {
$("#matiere").empty();
$.each(res, function (key, value) {
$("#matiere").append('<option
value = "'+key+'" > '+value+' < /option>');
});
} else {
$("#matiere").empty();
}
}
});
} else {
$("#matiere").empty();
}
});
</script>
#endsection
Routes:
Route::resource('dropdownlists','DropdownlistController');
Route::get('get-state-list','DropdownController#getStateList');
Route::get('get-city-list','DropdownController#getCityList');
Laravel has a very powerful and very useful feature that will make this easy for you, mutators. By adding a 'fullName' mutator, you can do this in the model any time you want. Then, in your controllers, you can call the function as if it was a field.
So, on your Eleve model:
public function getFullNameAttribute(){
return $this->prenom. " " . $this->nom;
}
Then in any controller, like when you want to send these to a dropdown, you can just get your collection, and then transfer it into the array you need.
Get the collection:
$elevesCollection = \App\Eleve::orderBy('nom')->select('prenom', 'nom', 'id')->get();
Then, pull the full name and the id from the collection:
$eleves = $elevesCollection ->pluck('name', 'id')->toArray();
You can send that through to your form dropdown. Please double check my code / spelling, but this should do what you wish.
I have a table where I get the data from database than i need to update all rows at once. Inside each cell I have added input fields. Now i want to be able to update all users at once when I enter the data but I dont know how.
Below is a picture of my view:
#extends('admin/master')
#section('content')
<section class="content">
{{Form::open()}}
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<div class="col-lg-4">
<h3 class="box-title">INPUT EXAM RESULTS FOR EACH STUDENT: </h3>
</div>
<div class="pull-right col-lg-8">
<div class="col-lg-2 col-lg-offset-5 pull-left">
<select class="btn bg-navy" name="city" >
<option>Select City</option>
<option>Prishtin</option>
<option>Prizren</option>
</select>
</div>
<div class="col-lg-5 pull-right">
<div class="input-group">
<input type="text" name="search_input" class="form-control" placeholder="Search here...">
<div class="input-group-btn">
<button type="submit" class="btn btn-info"><i class="fa fa-search"></i> Search</button>
</div>
</div>
</div>
</div>
</div>
<div class="box-body">
<?php if (isset($data)) { ?>
<table id="example2" class="table table-bordered table-hover">
<thead>
<tr>
<th>{{Lang::get('messages.stid')}} </th>
<th>{{Lang::get('messages.name')}}</th>
<th>Subject 1</th>
<th>Subject 2</th>
<th>Subject 3</th>
<th>Subject 4</th>
</tr>
</thead>
<tbody>#foreach ($data as $row)
<tr>
<td>{{$row->id}}</td>
<td>{{$row->fname}} {{$row->lname}}</td>
<td><input type="text" name="sub1" class="form-control" placeholder="Add marks here..."></td>
<td><input type="text" name="sub2" class="form-control" placeholder="Add marks here..."></td>
<td><input type="text" name="sub3" class="form-control" placeholder="Add marks here..."></td>
<td><input type="text" name="sub4" class="form-control" placeholder="Add marks here..."></td>
</tr>
#endforeach
</tbody>
</table>
<button type="submit" class="col-lg-2 pull-right btn btn-success"><i class="fa fa-save"></i> Save</button>
<?php } ?>
</div>
</div>
</div>
</div>
{{Form::close()}}
</section>
{{ HTML::script('/admin/assets/js/jquery-2.2.3.min.js') }}
{{ HTML::script('/admin/assets/js/bootstrap.min.js') }}
{{ HTML::script('/admin/assets/js/jquery.dataTables.min.js') }}
{{ HTML::script('/admin/assets/js/dataTables.bootstrap.min.js') }}
<script>
$(function () {
$("#example1").DataTable();
$('#example2').DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false
});
});
</script>
#stop
//Controller
public function search_input(){
$input = Input::get('search_input');
$city = Input::get('city');
$data = Apply::where('exam_venue', '=', "$input")
->where('city_applied', '=', "$city")->get();
if (isset($_POST['save'])) {
}
return View::make('admin/exam/edit',compact('data'));
}
Your input elements need to be arrays, keyed by $row->id (I assume this is the primary key of your students table) to identify which student that row represents. For example:
<td><input type="text" name="sub1[{{ $row->id}}]" class="form-control" placeholder="Add marks here..."></td>
Then when you submit the data, look up the student by the array key and update their information accordingly. Something to the effect of:
$key = // extract id from sub1 array
Student::find($request->input($key));
// do updates here
// repeat for each sub input...
Hi Guys i just need some help on my download page in my project because i need to have a download page that get files from different folders all of the folder is in the public path do you have some ideas for this i am using a page just like the link below just ignore the other button.
Download Page
i just tried ajax for this but it doesn't work
this my view:
#include('partials.navbar')
<link rel="stylesheet" type="text/css" href="http://localhost:8000/assets/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="http://localhost:8000/assets/css/search.css">
<!-- Search -->
<div class="container">
<!-- Search -->
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="input-group" id="adv-search">
<input type="text" class="form-control" placeholder="Search file" />
<div class="input-group-btn">
<div class="btn-group" role="group">
<div class="dropdown dropdown-lg">
<button type="button" class="set-width btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><span class="caret"></span></button>
<div class="dropdown-menu dropdown-menu-right" role="menu">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="file">File type</label>
<select class="form-control">
<option value="pf">Public Weather Forecast</option>
<option value="sf">24 Shipping Forecast</option>
<option value="gale">Gale Warning Forecast</option>
<option value="advisory">Weather Advisory</option>
<option value="tca">Tropical Cyclone Advisory</option>
<option value="swb">Severe Weather Bulletin</option>
<option value="iws">International Warning for shipping</option>
<option value="wof">Weather Outlook Forecast</option>
<option value="spf">Special Forecast</option>
<option value="sm">Surface Maps</option>
</select>
</div>
<div class="form-group">
<label for="date">Date</label>
<input class="form-control" type="date" />
</div>
<div class="form-group">
<label for="file">File name</label>
<input class="form-control" type="text" />
</div>
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
<button type="button" class="btn btn-primary"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--- Datatable -->
<div class="container">
<div class="row">
<div class="col-md-12">
<h4>Downloads</h4>
<table id="mytable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>File Name</th>
<th>Date Issued</th>
<th>File ID Number</th>
<th>Uploader</th>
<th>Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th>File Name</th>
<th>Date Issued</th>
<th>File ID Number</th>
<th>Uploader</th>
<th>Action</th>
</tr>
</tfoot>
<tbody>
#foreach ($files as $files2)
<tr>
<td>{{ $files2->file_name }}</td>
<td>{{ $files2->date }}</td>
<td>{{ $files2->id }}</td>
<td>{{ $files2->username }}</td>
<td><a data-id="{{ $files2->id }}" href="/download" class="btn btn-primary btn-xs dload-button" ><i class="fa fa-download"></i></a>
<button data-id="" class="btn btn-primary btn-xs dload-button" data-title="Dload" data-toggle="modal" data-target="#dload-modal"><i class="fa fa-file-text"></i></button></td>
</tr>
#endforeach
</tbody>
</table>
<input type="hidden" name="id" value="">
<input type="hidden" name="type" value="">
<input type="hidden" name="filename" value="">
</div>
</div>
</div>
</div>
#include('partials.footer')
<script type="text/javascript" src="http://localhost:8000/assets/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="http://localhost:8000/assets/js/dropdown.js"></script>
<script type="text/javascript" src="http://localhost:8000/assets/js/datatable.js"></script>
<script>
$(function() {
$(".dload-button").click(function(){
var param = $(this).data('id');
$.ajax({
url: "/downloadfile/" + param,
success: function(msg){
var dload = JSON.parse(msg)[0];
console.log(dload)
$('#id').val(dload.id);
$('#type').val(dload.file_type);
$('#filename').val(dload.upload);
},
error:function(){
alert("failure");
}
});
});
});
my controller:
public function dloadFile($id)
{
$files = Files::where('id',$id)
->get();
return json_encode($files);
}
public function getDownload()
{
$id = Input::get('id');
$files = Files::where('id',$id)
->first();
$ftype = $files->file_type = Input::get('type');
$filename = $files->upload = Input::file('filename');
$file= public_path(). "uploads/{$ftype}";
$headers = array(
'Content-Type: => application/pdf',
);
return Response::download($file, '{$filename}', $headers);
}
my route:
Route::get('/downloadfile/{id}', 'FileController#dloadFile');
Route::get('/download', array('uses' => 'FileController#getDownload'));
Any idea is much more appreciated Thanks in advance!.
there is no need to use Ajax for download. there is my code to download product image.in view file there is download link.
<a data-id="{{ $product->id }}" href="/productCRUD/{{$product->id}}/download" class="btn btn-primary btn-xs dload-button" ><i class="fa fa-download">Download</i></a>
in routes.php
Route::get('productCRUD/{product}/download', 'ProductCRUDController#download');
in productCRUDController.php
public function download($id)
{
$files = Product::where('id',$id)
->first();
$ftype = $files->file_type = Input::get('type');
$fullPath= public_path(). "/uploads/{$files->filePath}";
$headers = array(
'Content-Type: => application/jpg',
);
return Response::download($fullPath,$files->filePath, $headers);
}
with this code when you click on download link you get the file in your downloads folder.
I have a situation where a student may have multiple course. So when I select a student multiple course related to that student should load from database with the help of ajax. But in my ajax view it's only loaded second data and with the change of selection of other student nothing change in the view page. Previous data's only shown. But I have checked in console. it's showing correctly. How do I solve this problem? Anyone can help me to find the solution?
Here is my route:
Route::post('ajax-result',[
'uses'=>'ResultController#ajax_result',
'as'=>'ajax-student'
]);
Here is the controller:
public function ajax_result(Request $request)
{
$std_id= $request->input(['std_id']);
$student = DB::table('results')->join('grades','results.grade_id', '=','grades.id')
->join('courses', 'results.course_id', '=', 'courses.id')
->join('students', 'results.student_id', '=', 'students.id')
->join('departments','students.department_id','=','departments.id')
->where('students.id', $std_id)
->selectRaw('students.name,students.email,departments.name as d_name,
courses.name as c_name,courses.code as c_code,grades.grade')
->get();
return \Response::json($student);
}
And Here is the view with ajax:
<div class="container" >
<h3> View Result </h3>
<div class="form-group">
<label for="">Student Reg No.</label>
<select class="form-control input-sm" required id="student" name="student_id" >
<option>Select a Student</option>
#foreach($student as $row)
<option value="{{$row->id}}">{{$row->registraion_number}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label>Name</label>
<input type="text" name="name" id="name" class="form-control" >
</div>
<div class="form-group">
<label>Email</label>
<input type="text" name="email" id="email" class="form-control" >
</div>
<div class="form-group">
<label>Department</label>
<input type="text" name="department" id="department" class="form-control" >
</div>
<table class="table table-striped table-bordered" id="example">
<thead>
<tr>
<td>Serial No</td>
<td>Course Code</td>
<td>Name</td>
<td>Grade</td>
</tr>
</thead>
<tbody>
<?php $i=1; ?>
<tr>
<td>{{$i}}</td>
<td id="code_{{$i}}"></td>
<td id="name_{{$i}}"></td>
<td id="grade_{{$i}}"></td>
</tr>
<?php $i++; ?>
</tbody>
</table>
</div>
<script type="text/javascript">
$('#student').on('change',function(e){
$('#course').find('option').remove().end();
var std_id = $('#student option:selected').attr('value');
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: "POST",
url : "{{url('ajax-student-result')}}",
data:{std_id:std_id},
success : function(data) {
$.each(data,function(index,subcatObj){
$('#name').val(subcatObj.name);
$('#email').val(subcatObj.email);
$('#department').val(subcatObj.d_name);
$('#code_'+index).html(subcatObj.c_code);
$('#name_'+index).html(subcatObj.c_name);
$('#grade_'+index).html(subcatObj.grade);
});
}
});
});
</script>
I am developing a web application , there comes a scenario where user can insert multiple records at once.I created a Form at route result/create where user can add multiple row in front end , now when the user click on submit i want all the records/rows data which is in array form inserted into database.For now when i hit submit i get this error Undefined index: id.
PS : I am using Laravel 5.2 , and resource controller.
Adding Records View:
#extends('layouts.app')
#section('content')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('.add').click(function () {
var n = ($('.resultbody tr').length - 0) + 1;
var tr = '<tr><td class="no">' + n + '</td>' +
'<td><input type="text" class="name form-control" name="name[]" value="{{ old('name') }}"></td>'+
'<td><input type="text" class="fname form-control" name="fname[]" value="{{ old('fname') }}"></td>'+
'<td><input type="text" class="rollno form-control" name="rollno[]" value="{{ old('rollno') }}"></td>'+
'<td><input type="text" class="obtainedmarks form-control" name="obtainedmarks[]" value="{{ old('email') }}"></td>'+
'<td><input type="text" class="totalmarks form-control" name="totalmarks[]"></td>'+
'<td><input type="text" class="percentage form-control" name="percentage[]"></td>'+
'<td><input type="button" class="btn btn-danger delete" value="x"></td></tr>';
$('.resultbody').append(tr);
});
$('.resultbody').delegate('.delete', 'click', function () {
$(this).parent().parent().remove();
});
});
</script>
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Add Results</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/result') }}">
{!! csrf_field() !!}
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Student Name</th>
<th>Father Name</th>
<th>Roll No</th>
<th>Obtained Marks</th>
<th>Total Marks</th>
<th>%</th>
<th>Delete</th>
</tr>
</thead>
<tbody class="resultbody">
<tr>
<td class="no">1</td>
<td>
<input type="text" class="name form-control" name="name[]" value="{{ old('name') }}">
</td>
<td>
<input type="text" class="fname form-control" name="fname[]" value="{{ old('fname') }}">
</td>
<td>
<input type="text" class="rollno form-control" name="rollno[]" value="{{ old('rollno') }}">
</td>
<td>
<input type="text" class="obtainedmarks form-control" name="obtainedmarks[]" value="{{ old('email') }}">
</td>
<td>
<input type="text" class="totalmarks form-control" name="totalmarks[]">
</td>
<td>
<input type="text" class="percentage form-control" name="percentage[]">
</td>
<td>
<input type="button" class="btn btn-danger delete" value="x">
</td>
</tr>
</tbody>
</table>
<center><input type="button" class="btn btn-lg btn-primary add" value="Add New Item">
<input type="submit" class="btn btn-lg btn-default" value="Submit"></center>
</form>
</div>
</div>
</div>
</div><!-- First Row End -->
</div> <!-- Container End -->
#endsection
Student Controller:
public function store(Request $request)
{
$input = Input::all();
$condition = $input['id'];
for($id = 0; $id<$condition; $id++){
$student = new Student;
$student->name = $input['name'][$id];
$student->save();
}
return view('students.index');
}
You're getting that error because you have no id form field. Try this:
public function store(Request $request)
{
$input = Input::all();
$condition = $input['name'];
foreach ($condition as $key => $condition) {
$student = new Student;
$student->name = $input['name'][$key];
$student->fname = $input['fname'][$key];
$student->rollno = $input['rollno'][$key];
$student->obtainedmarks = $input['obtainedmarks'][$key];
$student->totalmarks = $input['totalmarks'][$key];
$student->percentage = $input['percentage'][$key];
$student->save();
}
return view('students.index');
}