This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
iillexial5598
I want to create dropdown for select category when i create photo in my plugin: My category table migration:
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('title');
$table->timestamps();
And photos table migration:
$table->engine = 'InnoDB';
$table->increments('id');
$table->text('description');
$table->integer('category_id')->unsigned()->index();
$table->foreign('category_id')->references('id')->on('zaweb_gallery_categories');
$table->timestamps();
And Photos model
<?php namespace Zaweb\Gallery\Models;
use Model;
use Zaweb\Gallery\Models\Categories;
/**
* Photos Model
*/
class Photos extends Model
{
/**
* @var string The database table used by the model.
*/
public $table = 'zaweb_gallery_photos';
/**
* @var array Guarded fields
*/
protected $guarded = ['*'];
/**
* @var array Fillable fields
*/
protected $fillable = [];
/**
* @var array Relations
*/
public $belongsTo = [
'category' => ['Zaweb\Gallery\Models\Categories']
];
public function getCategoryIdOptions()
{
$model = Categories::with('id', 'title');
return $model;
}
}
My fields.yaml:
fields:
description:
label: "Photo description"
category_id:
label: "Category"
type: dropdown
But my dropdown empty. Why? where I made a mistake? categories table not empty
iillexial5598
I chane
$model = Categories::with('title', 'id');
to
$model = Categories::lists('title', 'id');
And it's working
Last updated
1-2 of 2