public function create()
 {
     $subject = new Subject();
     $subject->name = Input::get('name');
     $subject->type_id = Input::get('type');
     $subject->save();
     Session::flash('message', 'Subject created.');
     return Redirect::back();
 }
Пример #2
0
 public function destroy($id)
 {
     $type = Type::find($id);
     $type->attributes()->detach();
     // Need to reset all subjects that use this type via foreign key
     // Had better make a warning message to explain that this will
     // happen and have the user confirm
     $subjects = Subject::where('type_id', '=', $id)->update(array('type_id' => 1));
     $type->delete();
     Session::flash('message', 'Type deleted.');
     return Redirect::back();
 }
Пример #3
0
 public function index($id)
 {
     $subject = Subject::find($id);
     $attributes = $subject->type->attributes;
     $activeColumns = array();
     // attributes assigned to the subject through type
     foreach ($attributes as $attribute) {
         array_push($activeColumns, $attribute->alias);
     }
     $data = Data::where('subjectID', '=', $id)->get();
     $allColumns = array();
     // all columns that have been entered into the data (it's schemaless)
     foreach ($data as $row) {
         foreach ($row->toArray() as $columnName => $value) {
             if (!in_array($columnName, $allColumns) && $columnName != '_id' && $columnName != 'updated_at' && $columnName != 'created_at' && $columnName != 'subjectID') {
                 array_push($allColumns, $columnName);
             }
         }
     }
     $extraColumns = array_diff($allColumns, $activeColumns);
     // the columns in the dataset that are not attributes assigned to the subject
     return \View::make('admin::data.index')->with(array('activeColumns' => $activeColumns, 'extraColumns' => $extraColumns, 'data' => $data));
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $subjects = Subject::all();
     return \View::make('admin::settings')->with(array('subjects' => $subjects));
 }