Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eloquent whereHasNot is missing

I need to access eloquent's whereHasNot method (added here:
https://github.com/laravel/framework/commit/8f0cb08d8ebd157cbfe9fdebb54d2b71b0afaabd)

I have laravel/framework (v5.1.20) installed via composer. However, the method does not exist in my /Illuminate/Database/Eloquent/Builder.php file.

Here is what I have in composer.json

"laravel/framework": "5.1.*",

Am I missing somewhere here?

If I'm not able to add this via composer, how can I extend Eloquent within my app to add this method?

Thanks!

like image 680
Marty Thomas Avatar asked Oct 21 '15 18:10

Marty Thomas


People also ask

What is with () in Laravel?

with() function is used to eager load in Laravel. Unless of using 2 or more separate queries to fetch data from the database , we can use it with() method after the first command. It provides a better user experience as we do not have to wait for a longer period of time in fetching data from the database.

How do you use whereHas?

Sometime we need to add where condition with relation table then you need to use wherehas() method. for example if you have users with country relation then you want to filter with country then you must have to use whereHas().

Does Laravel 8 have one relation?

hasOne relationship in laravel is used to create the relation between two tables. hasOne means create the relation one to one. For example if a article has comments and we wanted to get one comment with the article details then we can use hasOne relationship or a user can have a profile table.

What is belongsTo in Laravel?

BelongsTo relationship in laravel is used to create the relation between two tables. belongsTo means create the relation one to one in inverse direction or its opposite of hasOne. For example if a user has a profile and we wanted to get profile with the user details then we can use belongsTo relationship.


1 Answers

It was renamed to whereDoesntHave on Dec 17, 2014.

/**
 * Add a relationship count condition to the query with where clauses.
 *
 * @param  string  $relation
 * @param  \Closure|null  $callback
 * @return \Illuminate\Database\Eloquent\Builder|static
 */
public function whereDoesntHave($relation, Closure $callback = null)
{
    return $this->doesntHave($relation, 'and', $callback);
}
like image 69
whoacowboy Avatar answered Sep 16 '22 15:09

whoacowboy