How Select A Single Row October Cms

- 1 answer

How to select a single row on october cms?

How can a simple thing be so complicated here?

I thought it would be something to help us and not to disturb something that is as simple as

SELECT * FROM `engegraph_forms_membros` 

Here it's like fighting against demons without a bible, oh god why? Why make the query difficult for newbie?



I understand you don't speak English natively but you should watch every single one of these videos.

Does the record belong to a model in a plugin? Here are the docs on how to work with models.

You make a plugin, set the database which creates models, and then make components to be ran in your CMS Pages.

In a component.php file you can have something like this: Here I am calling the model class Agreements with use Author\Plugin\Models\Agreements;. This allows me to run a function/method to retrieve all agreements or one agreements using laravel's eloquent collection services.

Lets say we have the ID of a record. Well we can either call on the Agreements model with ::find or with ::where. You will noticed I have two functions that essentially do the same thing. ::find uses the primary key of the models (in my case the id) and will return a singular record. *Note that find can take an array and return a collection of records; like ::where. Using ::where we are going to look for the ID. *Note ::where always returns a collection which is why I have included ->first().

<?php namespace Author\Plugin\Components;

use Session;
use Input;
use Crypt;
use Db;
use Redirect;
use Illuminate\Contracts\Encryption\DecryptException;
use October\Rain\Support\Collection;

use Author\Plugin\Models\Agreements;

class GetAgreement extends \Cms\Classes\ComponentBase
    public function componentDetails()
        return [
            'name' => 'Get one agreement',
            'description' => 'Get an agreement to change or delete it'

    public function onRun() {
        $this->page['agreement'] = $this->getWithFindAgreement;

    public function getWithFindAgreement() {
        $id = 1;
        $agreement = Agreements::find($id);
        return $agreement;

    public function getWithWhereAgreement() {
        $id = 1;
        $agreement = Agreements::where($id)->first();
        return $agreement;

If for some reason you aren't working with models, here are the docs to work with Databases. You will have to register the use Db; facade.

Here call the table you want and use ::where to query it. *Note the use of ->first() again.

$users = Db::table('users')->get();
$user = $users->where('id', 1)->first();