Pertains to one of the elements in #1397 - timestamps and user_id's for Custom Fields

This commit is contained in:
Brady Wetherington
2015-12-30 15:58:51 -08:00
parent 7c06cba647
commit ad144e127c
5 changed files with 83 additions and 3 deletions
@@ -8,6 +8,7 @@ use Validator;
use Redirect;
use Model;
use Lang;
use Sentry;
class CustomFieldsController extends \BaseController {
@@ -43,7 +44,7 @@ class CustomFieldsController extends \BaseController {
public function store()
{
//
$cfset=new CustomFieldset(["name" => Input::get("name")]);
$cfset=new CustomFieldset(["name" => Input::get("name"),"user_id" => Sentry::getUser()->id]);
$validator=Validator::make(Input::all(),$cfset->rules);
if($validator->passes()) {
$cfset->save();
@@ -76,7 +77,7 @@ class CustomFieldsController extends \BaseController {
public function storeField()
{
$field=new CustomField(["name" => Input::get("name"),"element" => Input::get("element")]);
$field=new CustomField(["name" => Input::get("name"),"element" => Input::get("element"),"user_id" => Sentry::getUser()->id]);
if(!in_array(Input::get('format'),["ALPHA","NUMERIC","MAC","IP"])) {
$field->format=Input::get("custom_format");
} else {
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddTimestampAndUserIdToCustomFields extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('custom_fields', function(Blueprint $table)
{
$table->integer("user_id")->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('custom_fields', function(Blueprint $table)
{
$table->dropColumn("user_id");
});
}
}
@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddTimestampAndUserIdToCustomFieldsets extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::table('custom_fieldsets', function(Blueprint $table)
{
$table->timestamps();
$table->integer("user_id")->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('custom_fieldsets', function(Blueprint $table)
{
$table->dropTimestamps();
$table->dropColumn("user_id");
});
}
}
+4
View File
@@ -71,6 +71,10 @@ class CustomField extends Elegant
public function fieldset() {
return $this->belongsToMany('CustomFieldset'); //?!?!?!?!?!?
}
public function user() {
return $this->belongsTo('User');
}
//public function
+4 -1
View File
@@ -2,7 +2,6 @@
class CustomFieldset extends Elegant
{
protected $guarded=["id"];
public $timestamps=false;
public $rules=[
"name" => "required|unique:custom_fieldsets"
@@ -16,6 +15,10 @@ class CustomFieldset extends Elegant
return $this->hasMany('Model',"fieldset_id");
}
public function user() {
return $this->belongsTo('User'); //WARNING - not all CustomFieldsets have a User!!
}
public function validation_rules()
{
$rules=[];