Reputation: 925
I'm having some trouble with my school project as it is the first time i am using a framework and i need some guidance .
I am trying to update one of my databases but i can't find any way to get the class variable for the specific user/course.
I can't seem to find what i'm looking for in the laravel documentation as well.
Such as , to modify a user value in the database , the following works :
$student = Auth::user();
$student->firstname = Input::get('firstname');
$student->save();
However now , i created a new Class + Model that contains the username of a student & a course_id & the grade . the create function is below :
$com = new Com;
$com->student_username = Auth::user()->username;
$com->course_id = Input::get('course_id');
$com->grade = Input::get('grade');
$com->save();
Now i created a new function to update one of the Com , but i have no idea how to access the Com object for the specific one i want to update .
This is what i tried but doesn't work :
$com = ((Com->course_id == Input::get('course_id')) && (Com->username == Auth::user()->username)); // Doesn't Work
$com->grade = Input::get('grade');
$com->save();
Any help would be greatly appreciated - Thanks
Upvotes: 0
Views: 196
Reputation: 4532
You can use the excellent query builder that's build in Laravel:
<?php
$com = Com::where('course_id', '=', Input::get('course_id'))->where('username', '=', Auth::user()->username)->first();
$com->grade = Input::get('grade');
$com->save();
You can read more about the query builder in the Laravel docs.
Upvotes: 3