0

I made a library class that I am using for some common functions not provided by Laravel. It's been loaded into /config/app.php under the 'aliases' array, so that shouldn't be the problem.

When I call a method from my class ("InfoParse"), my conroller returns a blank page. I think this has to do with the fact that I'm calling a method from the library which uses Eloquent to interface with the database. I tried adding

use Illuminate\Database\Eloquent\Model;

to the top of the file, but that didn't help either.

Is there a specific way I should be setting up my class file so I can use either the DB:: class or Eloquent class?

Below is the function in question:

    /**
    * Check to see if this student is already recorded in our student table.
    * If not, add the entry, then return true. 
    * @param int $cwid
    * @return boolean
    */
    public static function checkStudentTableRecords($cwid)
    {
        if(Student::where('cwid', '=', $cwid)->count() != 0)
        {
            return TRUE;
        }
        else 
        {   ##insert the student into our student table
            $studentInfo = self::queryInfoFromCWID($cwid);

            $studentEntry = new Student;
                $studentEntry->cwid = $cwid;
                $studentEntry->fName = $studentInfo['fName'];
                $studentEntry->lName = $studentInfo['lName'];
                $studentEntry->email = $studentInfo['email'];
            $studentEntry->save();

            return TRUE;
        }
    }

(note: the self::queryInfoFromCWID() function is calling a function defined earlier in the class)

1 Answer 1

3

After some investigation, it turns out I need to format my Eloquent Model calls like this:

if(\Student::where('cwid', '=', $cwid)->count() != 0)

...

$studentEntry = new \Student;

The backslash is necessary to avoid namespace collision within the Laravel4 application.

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

1 Comment

Actually \` at the beginning indicates global/root namespace.

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.