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!
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.
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().
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.
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With