octobercms

Querying Many to One to Relation in October CMS as a Join

蓝咒 提交于 2019-12-11 14:54:42
问题 Given the following October CMS Plugin Models: Schema::create('iaff106_cellphone_cellphones', function($table){ $table->engine = 'InnoDB'; $table->increments('id'); $table->integer('user_id')->unsigned()->nullable()->index(); $table->string('label'); $table->string('phone')->nullable()->index(); $table->integer('provider_id')->nullable(); $table->boolean('is_txtable')->default(true); $table->boolean('is_published')->default(false); $table->timestamps(); }); Schema::create('iaff106_cellphone

How to listen for relation add events?

我的未来我决定 提交于 2019-12-11 07:27:30
问题 I want to call a function when a related model is added in the backend. This can be achieved by using a pivot model but in that case there must be some pivot data, otherwise the pivot model events are not fired. I dont need any pivot data but just to listen for the relation added event. 回答1: I think this was solved see this pull request and API Docs. They added 4 events for Many-to-Many relations : afterAttach, afterDetach, beforeAttach and beforeDetach 回答2: Well what you ask is complicated

OctoberCMS image(file) validation not working properly

久未见 提交于 2019-12-11 05:57:27
问题 I am trying to put image(file) validations in my model file but it seems to be not working as I want.Here below is my scenario. fields.yaml fields: slider_image: label: 'Slider Image (jpg,png,gif) (1920 X 600)' mode: image fileTypes: 'jpeg,jpg,png,gif' useCaption: true thumbOptions: mode: crop extension: auto span: auto required: 1 type: fileupload Model.php public $rules = [ 'slider_image' => 'required|mimes:jpeg,jpg,png,gif', ]; public $customMessages = [ 'slider_image.required' => 'Please

Making a deep related field searchable in OctoberCMS

試著忘記壹切 提交于 2019-12-11 05:19:03
问题 My my columns.yaml file for the Invoice model I have the following column: transaction[user][email]: label: Login email type: text searchable: true // doesn't work! Unfortunately, the searchable bit doesn't work and I understand that this is because I am using transaction[user][email] instead of having a relation and select as part of the column. My question is, can I somehow use relation and select when I'm going 2 relations deep, like this, or do I need a different approach? My Invoice

Scope query in a many to many relationship

Deadly 提交于 2019-12-11 04:37:30
问题 I created 2 models, "Post" and "Category". This is a many to many relationship, works great. My tables are the following : alex_blog_posts : where posts are stored with columns like "title", "published" etc... alex_blog_categories : where categories are stored with columns like "title", "parent_id" etc... alex_blog_posts_categories : where the relation is stored between posts and categories with columns "post_id", "category_id" Let's assume I want to filter all posts that are associated to a

How to call 2 Functions at the same time using Twig AJAX Form?

元气小坏坏 提交于 2019-12-11 04:28:37
问题 I'm using OctoberCMS based on Laravel and Twig. I'm using a Twig AJAX Form that has 2 buttons. Each call a PHP function, actionOne() and actionTwo() . How do I make the second button call both functions at the same time? Using multiple data-request on a button doesn't work. And using multiple functions separated by comma in data-request also doesn't work. Form {{ form_open() }} <button type="button" data-request="actionOne">Action 1</button> <button type="button" data-request="actionTwo"

afterSave() gives error trying to get property of non-object in octoberCMS

試著忘記壹切 提交于 2019-12-10 23:23:34
问题 i am trying to get path of uploaded file using fileupload widget and then copying that file in custom folder but when creating new record it gives error trying to get property 'path' of non-object when afterSave() calls. MODEL: public $attachOne = [ 'file' => ['System\Models\File'] ]; public function afterSave() { $path = $this->file->path; log::info($path); } 回答1: replace this afterSave method in your model and it will not show the error you are having. public function afterSave() {

How do I provide output to console when seeding or migrating tables?

一个人想着一个人 提交于 2019-12-10 18:33:04
问题 I have a plugin in october and i'm creating the neccessary tables and seeding them per the docs. I wish to provide console output when doing that so I can debug the process i'm setting up and catching any eventualities. How can I output information to console when running php artisan october:up ? use Db; use Seeder; class SeedGeoStateTable extends Seeder { public function run() { foreach(array_merge(glob(__DIR__.'/seed/geo_state/*.txt'), glob(__DIR__.'/seed/geo_state/*.json')) as $file) {

October CMS: How to extend the backend user with role scope

拜拜、爱过 提交于 2019-12-10 18:23:02
问题 I've been able to extend the Backend\Models\User class and add a scoped query method to retrieve only super users: public function boot() { User::extend(function($model) { $model->addDynamicMethod('scopeIsSuperUser', function($query) { return $query->where('is_superuser', 1); }); }); } How can I have a scope method for users who are in a specific group? Like I only want users whose role is " BookManager ". Is it possible to use the $groups relation already defined on the Backend\Models\User

Media Finder display Image on Front End

青春壹個敷衍的年華 提交于 2019-12-10 12:00:00
问题 I created a Model and Database and can upload an image using the Media Finder. I set Media Finder field as photo in fields.yamal . But after uploading, no image path is saved to the database in the photo column. Database Tables id (integer) title (string) photo (string) Twig {% for product in builderListCatalog.records %} {{ product.title }} <img src="{{ product.photo }}" /> {% endfor %} This successfully displays the Title but not the Photo path because it is empty in the database. 回答1: You