Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Yii2 GridView Filtering on Relational Column

class UserSearch extends User
{
    public $company_name;
    public function rules()
    {
        return [
            [['first_name', 'last_name', 'email', 'company_name'], 'safe']
        ];
    }

    public function search()
    {
        $query = User::find();
        $query->joinWith(['client c']); //set relation alias

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query
            ->andFilterWhere(['like', 'first_name', $this->first_name])
            ->andFilterWhere(['like', 'last_name', $this->last_name])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', "c.company_name", $this->company_name]);

        return $dataProvider;
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: upsert request php-salesforce-rest-api 
Php :: php curl upload linkedin image 
Php :: phpmyadmin account locked 
Php :: MForm Bild Attribute 
Php :: mac php.ini catalina 
Php :: pusher in laravel array_merge(): Argument #2 is not an array 
Php :: PHP strtr — Translate characters or replace substrings 
Php :: php notice: trying to access array offset on value of type bool in /usr/share/php/pear/rest.php on line 187 
Php :: Online Food Ordering System Project SQL 
Php :: laravel error reporting code for view 
Php :: larqavel migration 
Php :: replace class 
Php :: get count mini cart item total 
Php :: withCount laravel assign generic name 
Php :: merge two entity symfony 
Php :: old codestar textarea field 
Php :: get vendor store url dokan 
Php :: php decrement variable by 1 
Php :: CarbonTraitsUnits.php:69 
Php :: export data to excel in codeigniter using phpexcel 
Php :: how to create pdf with doompdf in php 
Php :: nl2br is not working for database in php 
Php :: try/catch -- much needed 
Php :: laravel orm latest() 
Php :: How to Validate an Email Duplicate Entry in Codeigniter 
Php :: Drupal 9 loop term objects to retrieve term data (id, name, uuid) 
Php :: php json array push in js file 
Php :: codecept run single test 
Php :: section laravel append 
Php :: laravel how to call function in same controller 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =