Yep, I understand why Postgres is throwing this error, but atm I have no idea “how to get” the necessary fields into the select clause.
I am not experiencing this problem with the built-in Sprunjes, which makes me almost certain that this problem occurs on my side (=my code).
Here is my Sprunje class:
<?php
namespace UserFrosting\Sprinkle\Tools\Sprunje;
use UserFrosting\Sprinkle\Core\Facades\Debug;
use UserFrosting\Sprinkle\Core\Sprunje\Sprunje;
use UserFrosting\Sprinkle\Tools\Database\Models\CustomerDataCompany;
class CustomerDataCompanySprunje extends Sprunje
{
protected $name = 'customerdata_company';
protected $sortable = [
'customerid',
'companyname',
'remarks',
'group',
'created_at',
'updated_at'
];
protected $filterable = [
'customerid',
'companyname',
'remarks',
'group',
'created_at',
'updated_at'
];
//protected $listable = [];
protected $listable = [
"customerid",
"companyname",
"remarks",
'group',
'created_at',
'updated_at'
];
/**
* Set the initial query used by your Sprunje.
*/
protected function baseQuery()
{
$instance = new CustomerDataCompany();
// Alternatively, if you have defined a class mapping, you can use the classMapper:
// $instance = $this->classMapper->createInstance('owl');
return $instance->newQuery();
}
}
The Migration class:
<?php
namespace UserFrosting\Sprinkle\Tools\Database\Migrations;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
use UserFrosting\Sprinkle\Core\Database\Migration;
class CustomerDataCompanyTable extends Migration
{
public function up()
{
if (!$this->schema->hasTable('customerdata_company')) {
$this->schema->create('customerdata_company', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('customerid')->unique();
$table->string('companyname');
$table->string('remarks');
$table->string('group');
$table->timestamps();
});
}
}
public function down()
{
$this->schema->drop('customerdata_company');
}
}
The Model class:
<?php
namespace UserFrosting\Sprinkle\Tools\Database\Models;
use Illuminate\Database\Capsule\Manager as Capsule;
use UserFrosting\Sprinkle\Core\Database\Models\Model;
class CustomerDataCompany extends Model
{
/**
* @var string The name of the table for the current model.
*/
protected $table = 'customerdata_company';
protected $fillable = [
'customerid',
'companyname',
'remarks',
'group',
'created_at',
'updated_at'
];
/**
* @var bool Enable timestamps for this class.
*/
public $timestamps = true;
}
Controller Class used for Sprunje:
public function getCustomerDataSearch($request, $response, $args)
{
// GET parameters
$params = $request->getQueryParams();
// access controlled page
$authorizer = $this->ci->authorizer;
$currentUser = $this->ci->currentUser;
$currentGroup = $currentUser->group_id;
// alert stream
$ms = $this->ci->alerts;
if (!$authorizer->checkAccess($currentUser, 'view_page')) {
throw new ForbiddenException();
}
/** @var UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
$classMapper = $this->ci->classMapper;
$sprunje = new CustomerDataCompanySprunje($classMapper, $params);
return $sprunje->toResponse($response);
}
Thanks for your help!