View on GitHub

Populate a Select From A Joined Table

I never remember how to do this.

Datatables Help

Parameters - easy database options

The Field->options() method accepts up to five parameters:

string - The database table name that the options should be read from string - The column name that contains the value for the list of options string|array - The column(s) that contain the label for the list of options (i.e. this is what the user sees in the select list)

This is the PHP

//Three parts
    Field::inst( 'temp_records.area_id' )
                    ->options('areas','id','description', function ($q) {
                        $q->where('areas.deleted_at', null);
                    ->validator( 'Validate::dbValues' ),
     Field::inst( 'areas.description' ),
       ->leftjoin('areas','','=','temp_records.area_id' )

This is the JS

						label: "Application:",
						name: "roles.application_id",
						placeholder: "Select an Application"


{ "data": "",editField:"roles.application_id"}

Datatables Discussion