A
A
Alexander2019-01-17 16:44:11
Laravel
Alexander, 2019-01-17 16:44:11

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: 5c408ec681ca9545800336.jpeg
snapshot 2: 5c408ed44d907324503658.jpeg
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');
    }
}

But when saving record I get error Array to string conversion
snapshot 35c408ee95277f268194763.jpeg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question