last day (349 days later) » 

4:25 PM
Hello sir
 
Hi bro
how r u ?
 
Alhamdulillah
How are you ?
Ramzan Mubarak :)
 
fine lhamdolillah
Ramadan mubarak
:P
 
Ok sir let me explain my problem
I already did that in email
So i will cody that from there
 In the creating student report whenever user select a class in the dropdown then all the students ids and names comes up in the next dropdowns list related to that class. So in the database I have student id number (not the actual student id) and also for the name I have student name id like 1, 2 or 3... Because from the dropdown its taking its value. So now In the index table I am using ajax again where user can select class and all the reports according to that class will be shown but here its showing the student id number and student name id like 1, 2, or 3... So my point is how I can g
**Ajax**

$(document).ready(function () {

//FOR LOADING STUDENTS
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});

$('select[name="class_id"]').on('change', function () {
var classID = $(this).val();
if (classID) {

$.ajax({

url: '/reports/ajax/' + classID,
type: "GET",
dataType: "json",
success: function (data) {

var markup = '';
markup = '<thead><tr class="filters"><th style="width: 2%" class="align-middle text-center"><input type="checkbox" id="options"></th><th style="width: 15%" class="text-center">Student ID<input type="text" class="form-c
 
could you please share a screenshot so I can follow you
 
4:30 PM
Yeah i already did that briefly in email. But here i cannot share screenshot
I think that is because of my low reputation
:(
 
Ok let me check the email
 
Ok sir
 
ok let detail the description so we make sure I understand
In the creating student report whenever user select a class in the dropdown then all the students ids and names comes up in the next dropdowns list related to that class.
the first part says that you're selecting a class
from classes dropdown
 
when the screenshot from the email
doesn't contains any dropdown with the classes name
there's a :
report category
student Id
student name
 
4:34 PM
oh my bad. Sorry sir. yeah that report category is the class name
 
ok
now let move to the next part
 
So in the database I have student id number (not the actual student id) and also for the name I have student name id like 1, 2 or 3... Because from the dropdown its taking its value.
this part is a little flow
I mean why you're not storing the student id ? what is the "student id number"
 
Its actually storing the value of the student_id from the dropdown
 
and you're saying in database but you're not specifying the table
 
4:37 PM
So that is like some number 1 ,2 or 3
 
the value of student_id from the dropdown must be the "student_id"
why you're storing another number?
 
ok let me show you something
 
when you've control over the dropdown and you can set the value as "student_id" instead of 1,2,3
ok
 
I am creating new report and show you the backend from where it is saving that number
Then you will see
Give me just 5 mins
 
okey, take your time
 
4:50 PM
ok sir
<select class="form-control" name="student_id" id="student_id"><option value="1">hk123</option></select>
I copy it from the backend
You can see there value = "1"
Its actually saving that value
Now i cannot understand that how to get that actually student id which is hk123 from that 1
I tried to pluck it but did not work
This is actually what I mean
And the same thing happens with student name and also with report category field
 
what I mean is whay you don't generate the select the first time like :
<option value="hk123">hk123</option>
since you've already the student_id then you can affect it to the value too
Like an example, something like :
<option value="{{$student_id}}">{{$student_id}}</option>
could you share with me the code that generate the :
<select class="form-control" name="student_id" id="student_id"><option value="1">hk123</option></select>
?
 
<div class="form-group">
{!! Form::label('student_id', 'Student ID', ['class'=>'control-label', 'name'=>'student_id']) !!}
{!! Form::select('student_id', [''=>'Choose'], null, ['class'=>'form-control', 'name'=>'student_id']) !!}
</div>
<div class="form-group">
{!! Form::label('student_name', 'Student Name', ['class'=>'control-label', 'name'=>'student_name']) !!}
{!! Form::select('student_name', [''=>'Choose'], null, ['class'=>'form-control', 'name'=>'student_name']) !!}
</div>
I have these two things for the student_id and student_name
 
You need to get the list of id, name from the database then send it from the controller to this view
 
ok sir
let me do this first
 
$students_list = Student::pluck('id', 'name')->toArray();
return view('your_view')->compact('students_list');
just as a sample
 
4:59 PM
ok sir
 
Then in the view like :

{!! Form::select('student_id', [''=>'Choose']+$students_list, null, ['class'=>'form-control', 'name'=>'student_id']) !!}
 
yeah got it now
Column not found: 1054 Unknown column 'name' in 'field list' (SQL: select name, id from students)
This error
yeah fine
Its first_name
But still i have the same thing like value = "1" in the backend
 
try first to show me the output of dd( $students_list );
 
the output array of the first_name and the id
 
5:08 PM
array:1 [▼
  "hasnain" => 1
]
And also I need to pluck both the first_name and last_name
 
try pluck('name', 'id') instead
_But still i have the same thing like value = "1" in the backend_
:46179611 it must 1 since the id in the database is 1
 
When i try that then its giving me the error I showed you while aho
ago
 
change it in the database to 20
for example
so you can make sure that the value contains the "id"
 
array:1 [▼
  "hasnain" => 1
]
Same result
 
show me the code
please
 
5:12 PM
Fine sir. I reveresed the first_name and id
$students_list = Student::pluck('first_name', 'id')->all();
Like this
array:1 [▼
  1 => "hasnain"
]
Now its the result
 
yes
try to replace the id 1 in the database to 20
then try again
 
same result at the backend sir
And also same result in the table
 
dd( $students_list );
must return
array:1 [▼
20 => "hasnain"
]
if you change the id in the students table
manually
 
yeah
I did that
 
ok
now in the view
share with me the code you've
that generate the dropdown
 
5:17 PM
<div class="form-group">
{!! Form::label('class_id', 'Report Category', ['class'=>'control-label', 'name'=>'class_id']) !!}
{!! Form::select('class_id', [''=>'Choose'] + $classes, null, ['class'=>'form-control', 'name'=>'class_id']) !!}
</div>

<div class="form-group">
{!! Form::label('student_id', 'Student ID', ['class'=>'control-label', 'name'=>'student_id']) !!}
{!! Form::select('student_id', [''=>'Choose'] + $students_list, null, ['class'=>'form-control', 'name'=>'student_id']) !!}
</div>
 
try dd( [''=>'Choose'] + $students_list ); in the controller
and share the output with me please
 
ok
array:2 [▼
  "" => "Choose"
  1 => "hasnain"
]
 
you still get 1
when you've 20 in the database?
illogical
 
Ok let me change it back. Sorry
Oh. Its still giving me the same result
Even i changed the student_class_id to 20
array:2 [▼
  "" => "Choose"
  1 => "hasnain"
]
 
you're getting the id in "pluck('first_name', 'id')" not student_class_id
why you change "student_class_id" instead ?
 
5:22 PM
array:2 [▼
  "" => "Choose"
  20 => "hasnain"
]
Sorry :(
 
you need to change the 'id' field in the students table
 
yeah
you can see that now
 
it's ok
now the select must contain the id as value instead of 1,2,3
check it please
Imean it must look like :

<option value="">Choose</option>
<option value="20">hasnain</option>
 
So i need to remove dd( [''=>'Choose'] + $students_list ); this from the controller first
 
yes sure
it's just for debugging purpose
 
5:24 PM
<select class="form-control" name="student_id" id="student_id"><option value="20">hk123</option></select>
 
that good
 
<select class="form-control" name="student_name" id="student_name"><option value="20">hasnain khan</option></select>
 
now you get the reel id
 
so that solve the problem
So my point is how I can get the student actual id from that student id number and student name from that student name id
now you can store the exact values you want
in the column you want in the database
 
5:27 PM
So now i try it ?
 
yes you can play with this around for awhile, check If this will solve you're problem
since now you'll get the id and not the index
from the id you can get the information you want
now I will quit
you can contact me if you still have difficulties
 
Yeah sir. I knew it that i am getting the id. But i can't understand that how i can get the the information i want
I already tried it so much
 
Then wi'll fix another session to fix them
 
Ok sir
 
if you've the id
of the student
 
5:30 PM
I will try on it once again
Ok sir
I will contact if i did not solve it
 
then you can instanciate the student object and get the information you want
 
ok sir
Thank you so much for your time and support
 
$student = Student::find('the_id_you_get'),
$student->first_name
...
 
ok sir
 
I'm leaving
take care
and happy coding
 
5:31 PM
Allah hafiz
 
see you later
 
You too
 

  last day (349 days later) »