Answer the question
In order to leave comments, you need to log in
How to fix Array to string conversion error in Ortober CMS?
I recently started working with Ortober CMS, and I encountered an Array to string conversion error when creating an entry in the admin section.
There are two models Order and Service
Order - orders
Service - services
Many-to-many relationships through an intermediate table.
In Order, I display a list of services through a dropdown list.
In the administrative section of the site in the form for creating a new order, you must select one of the services in the list via dropdown.
snapshot 1:
snapshot 2:
I've retrieved the list of services using the getServicesOptions method.
namespace Alex\Services\Models;
use Model;
use Alex\Services\Models\Service;
/**
* Model
*/
class Order extends Model
{
use \October\Rain\Database\Traits\Validation;
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
public $timestamps = false;
/**
* @var string The database table used by the model.
*/
public $table = 'alex_services_orders';
/**
* @var array Validation rules
*/
public $rules = [
];
/*Relations*/
public $belongsToMany = [
'services' =>[
'Alex\Services\Models\Service',
'table' => 'alex_services_services_orders',
'order' => 'name'
]
];
public function getServicesOptions(){
return Service::lists('name', 'id');
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question