devianl2 / laravel-scorm

Laravel scorm package
MIT License
38 stars 20 forks source link

add doc for laravel builder dynamic where handler #10

Closed KhaledLela closed 1 year ago

KhaledLela commented 2 years ago

ScormModel::whereOriginFile()

From Laravel doc despite old version still supported. Dynamic Where Clauses You may even use "dynamic" where statements to fluently build where statements using magic methods:

$admin = DB::table('users')->whereId(1)->first();

$john = DB::table('users')
                    ->whereIdAndEmail(2, 'john@doe.com')
                    ->first();

$jane = DB::table('users')
                    ->whereNameOrAge('Jane', 22)
                    ->first();

Update

/**
     * Handle dynamic method calls into the method.
     *
     * @param  string  $method
     * @param  array  $parameters
     * @return mixed
     *
     * @throws \BadMethodCallException
     */
    public function __call($method, $parameters)
    {
        if (static::hasMacro($method)) {
            return $this->macroCall($method, $parameters);
        }

        if (str_starts_with($method, 'where')) {
            return $this->dynamicWhere($method, $parameters);
        }

        static::throwBadMethodCallException($method);
    }
KhaledLela commented 2 years ago

Not related to library but i added as searchable reference it may help others needs clean, short and readable dynamic where style.

Thanks!