Home > database >  how set fixed where query in model laravel
how set fixed where query in model laravel

Time:12-22

My site has 5 languages A column has been added for all tables with name language

How can be in the model of tables add where('language' , App::getLocale()) query when use select data in database ?

Scope is one solution but another way

Thanks for any idea

CodePudding user response:

You can overwrite the newQuery() function on your Language Model (app\Models\Language.php)

/**
 * Get a new query builder for the model's table.
 *
 * @return \Illuminate\Database\Eloquent\Builder
 */
public function newQuery()
{
    return parent::newQuery()->where('language', App::getLocale());
}
  • Related