Skip to content

Commit

Permalink
added user belongsTo relationship
Browse files Browse the repository at this point in the history
Signed-off-by: Fenn-25 <fenn25.fn@gmail.com>
  • Loading branch information
nfebe committed Oct 30, 2018
1 parent fb42790 commit 40a2146
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
8 changes: 8 additions & 0 deletions controllers/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,12 @@ public function onShowStat()

return $this->makePartial('show_stat');
}

/**
* Add user_id for user relationship before save
*/
public function formBeforeCreate($model)
{
$model->user_id = $this->user->id;
}
}
3 changes: 2 additions & 1 deletion models/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class Posts extends Model
'category' => [
'Indikator\News\Models\Categories',
'order' => 'name'
]
],
'user' => ['Backend\Models\User']
];

public $hasMany = [
Expand Down
23 changes: 23 additions & 0 deletions updates/add_user_field_to_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php namespace Indikator\News\Updates;

use October\Rain\Database\Updates\Migration;
use Schema;

class AddUserFieldToTable extends Migration
{
public function up()
{
Schema::table('indikator_news_posts', function($table)
{
$table->integer('user_id')->unsigned()->nullable()->index();
});
}

public function down()
{
Schema::table('indikator_news_posts', function($table)
{
$table->dropColumn('user_id');
});
}
}
3 changes: 3 additions & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,6 @@
- adding_custom_newsletter_content_fields_to_posts.php
1.10.5: Minor UI and code improvements.
1.10.6: Improved the mail statistics of user.
1.10.7:
- Added user relation.
- add_user_field_to_table.php

0 comments on commit 40a2146

Please sign in to comment.