0

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.