« first day (3 days earlier)    last day (345 days later) » 

12:03 PM
Hi
 
Hello sir
How are you
 
fine bro
and you ?
 
Alhamdulillah fine
 
lhamdo lilah
 
So I was trying on the thing we were discussing last time
 
12:11 PM
ok
 
Can you check the email please. I explained there something about that problem
 
ok 1 min
 
ok
my guessing is you're not receiving the proper id
so the instanciation return null
and you can't find the first_name
 
yeah
 
12:14 PM
inside an empty or null object
 
That's the case
 
so let me see your code
 
ok
public function index()
{
$classes = StudentsClass::pluck('class_name', 'id')->all();
$student = Student::find('id');
$student->first_name;
return view('admin.reports.index', compact('classes', 'student'));
}
First i just tried for the first name
is it correct ?
 
no
itsn't
 
Trying to get property 'first_name' of non-object
This is the error
 
12:16 PM
Student::find('id'); must be Student::find(the reel id I mean 1 or 2 or 20);
 
Yeah i was not sure about that. That's why
 
and you're passing a string "id"
 
oh fine
ok let me try that
 
so the query in the background will be like :
select * from students where id='id'
 
ok sir
got it now
 
12:17 PM
(y)
 
ok now its giving me no error
But the result is the same
 
if you're passing the right id
 
yeah it is the right id. 1. I checked it again
 
that you've in the database you must get the object try :

$student = Student::find(1);
dd( $student );
and show me the output
 
ok
Student {#337 ▼
  #fillable: array:23 [▶]
  #hidden: array:1 [▶]
  #connection: "mysql"
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:26 [▶]
  #original: array:26 [▶]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #visible: []
  #guarded: array:1 [▶]
 
12:20 PM
open the #attributes: array:26 [▶]
 
"id" => 1
    "student_id" => "hk123"
    "first_name" => "hasnain"
    "last_name" => "khan"
    "DOB" => "2017-03-13"
    "students_class_id" => 1
    "gender" => "male"
    "blood_group" => "a+"
    "religion" => "islam"
    "photo_id" => "1"
    "student_address" => "Some type of dummy text for address field"
    "student_phone_no" => 1234897
    "guardian_name" => "irshad"
    "guardian_gender" => "male"
    "guardian_relation" => "uncle"
    "guardian_occupation" => "engineer"
    "guardian_phone_no" => 123989
 
you must see the student information
 
yes
It is
 
ok
now what you want to do with this information ?
 
Now in the index I have table. In which these informations is showing but those were the ids as I told you. I just want to show the student real name and student real id instead of those ids
 
12:24 PM
show me the "admin.reports.index" view
 
Did you get my point
 
yes I think
 
can i send you the screenshot on the email
screenshot of the index
 
I want to see the code
 
12:25 PM
how you render the information inside the table
 
ok let me show you
@extends('layouts.dashboard')

@section('content')


@include('includes.report_nav')

	<!--HEADER-->
	<header id="main-header" class="py-2 header-backgroud text-white">
		<div class="ml-4">

			<a href="/" class="btn btn-danger">
				<i class="fas fa-arrow-left"></i> Back To Dashboard
			</a>

			<div class="row">
				<div class="col-md-6">

					<h1><i class="fas fa-list-alt"></i> Reports List</h1>
				</div>
			</div>

			<div class="d-flex text-white text-center">
				<a href="{{route('admin.reports.rep_cats.index')}}">
that ajax to get the student information to the table from the db
And that is showing me the ids
 
I need to see where the route "/reports/ajax/id" redirect
to which controller and action
 
so we can see what the ajax request return and how we can send the names instead of ids from there
 
 public function getStudentId($id) {
        $students = DB::table("students")->where("students_class_id",$id)->pluck("student_id","id");
        return json_encode($students);
    }

    public function getStudentName($id) {
        $students = DB::table("students")->select("id", DB::raw("CONCAT(first_name, ' ', last_name) as name"))
            ->where("students_class_id",$id)->pluck("name","id");
        return json_encode($students);
    }
public function myReportAjax($id) {
$reports = Report::where('class_id', $id)->get();
return json_encode($reports);
}
 
12:33 PM
I think the last one ?
 
ok I need to see the Report Model code
to know the relationship between it and the student/class
 
ok
 public function studentsClass() {
        return $this->belongsToMany('App\StudentsClass');
    }

    public function student() {
        return $this->belongsToMany('App\Student');
    }
Actually during the creation time as you know that i am getting the student name and id through an Id. As we dicussed few days ago. And that id is saving actually.
 
ok
so the problem now is just how getting the student name in the table
 
yes and also the report category and the student actual id
 
12:37 PM
can you show me the output of dd( Report::where('class_id', $id)->get() );
 
Because i am getting those numbers for all the fields which are saving through dropdown
 
if you replace the $id with the class_id you're testing with
 
ok let me try
 "id" => 1
        "student_id" => "1"
        "student_name" => "1"
        "class_id" => 1
        "subject" => "Maths"
        "teacher_name" => "Hasnain"
        "report_categories_id" => "1"
        "total_marks" => "5"
        "obtained_marks" => "3"
        "percentage" => "60.00"
        "position" => "1"
        "photo_id" => "2"
        "created_at" => "2019-05-14 12:17:52"
        "updated_at" => "2019-05-14 12:17:52"
Look here sir
As i told you i am getting ids
These are the ids
 
where you feel this table with those id's
 
12:42 PM
we can store the name instead in "student_name"
 
and what it the other column that you want to change his value
?
"report_categories_id" ?
 
yes
and student_id
 
or you want another column like report_categories_name
student_id already contains the right id, isn't it ?
 
No that is the same column at the back end
No that is another id like hk123
 
12:44 PM
ok show me where those values are stored
in which action
 
ok
public function store(ReportRequest $request) {

        $input = $request->all();

        if ($file = $request->file('photo_id')) {
            $name = time() . $file->getClientOriginalName();
            $file->move('images', $name);
            $photo = Photo::create(['file'=>$name]);
            $input['photo_id'] = $photo->id;
        }

        Report::create($input);
        return redirect()->back();
    }
 
add dd( $input );
just before
Report::create($input);
and try to store a new report then show me the output
 
ok
array:11 [▼
"_token" => "ezbzqia7L3UCYjoSGTUfk6w22TvO620rqvg3I1aX"
"class_id" => "1"
"student_id" => "1"
"student_name" => "1"
"subject" => "ads"
"teacher_name" => "asd"
"report_categories_id" => "1"
"total_marks" => "2"
"obtained_marks" => "2"
"percentage" => "100.00"
"position" => "1"
]
are you here sir ?
 
I'm here
 
ok sorry . take your time
 
12:54 PM
we will try something then I will quit for 1 hour then we'll continue
The thing I want you to try
is
 
ok sir
 
dd( Student::find( $input['student_id'] )->first_name )
before Report::create($input);
 
in the index ?
ok
"hasnain"
 
so replace it with $input['student_name'] = Student::find( $input['student_id'] )->first_name;
and check it the name will be stored in the database
instead of the id
this time
 
ok sir
let me check
 
12:57 PM
ok
 
yes sir
:)
So i will do the same thing for the rest ?
 
yes
the same technique
for the rest
 
ok sir
 
I will be here after an hour
 
Fine
 
12:59 PM
if you still have any questions
good luck
 
Ok sir but after an hour. here will be Aftaar :D
i will try it now'
 
aaaah
so iftar chahiy
contact me after that by mail
 
If there was some problem then i will email or just message here
haha :D
 
Ok sir
 
1:00 PM
see you later
 
Ok Thank you so much sir
Allah Bless you
 
Glad to help brother
 
See you later
 
 
2 hours later…
2:42 PM
Hello sir
Are you here ?
 
Hi
yes I'm here
 
ok Sir
Now in the reports table i have student_name and in the students table i have first_name and last_name
I want to get them both in that one column which is student_name
for that I did something like this
$input['student_name'] = Student::find( $input['student_id'] )->first_name;
$input['student_name'] = Student::find( $input['student_id'] )->last_name;
But its giving me then only the last name
 
it must be :
$student = Student::find( $input['student_id'] );
$input['student_name'] = $student->first_name.' '.$student->last_name;
 
ok let me try
yeah that's working now
 
2:54 PM
now for the report categories id I have different table
for which i tried this thing
ok that works
$input['report_categories_id'] = ReportCategories::find( $input['report_categories_id'] )->name;
Its working now with this
I have another issue but we will discuss it next time. Now i will just complete this thing
Ok sir ?
 
ok
it's ok
good job (y)
 
Ok thank you sir. Thanks for your time and support
Allah bless you
See you next time inshAllah
:)
 
You're welcome brother
incha llah
;)
 

« first day (3 days earlier)    last day (345 days later) »