/** * Store a newly created resource in storage. * * @return Response */ public function postCreate(ObjectRequest $request) { $object = new object(); if ($request->parent_id) { $object->parent_id = $request->parent_id; } else { $object->parent_id = null; } $object->author_id = Auth::user()->id; $object->type = 'category'; $object->name = preg_replace('[ ]', '-', strtolower($request->name)); $object->title = $request->title; $object->content = $request->content; $object->excerpt = $request->content; $object->status = 1; if ($request->get('score')) { $object->score = $request->get('score'); } $object->guid = str_replace(".", "", uniqid('', true)); $object->save(); return redirect('admin/categories')->with('message', 'Category saved successfully'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function postEdit(ObjectRequest $request, $id) { $object = Object::find($id); //$object->name = $request->name; $object->title = $request->title; $object->content = $request->content; $excerpt = strip_tags($request->content); $excerpt = preg_replace('/\\s+/', ' ', $excerpt); $object->excerpt = $excerpt; $object->save(); // if ($objecttype = Object::where('type', 'object_type') // ->where('name', '_object_type_' . $object['type'] ) // ->first() ) { // // if ( $fields = Object::getFields( $objecttype['id'] )->get() ) { // foreach ( $fields as $field ) { // if ( $fieldInfo = unserialize( $field['meta_value'] ) ) { // $value = Input::get($fieldInfo['id']); // // echo $value; // } // } // } // } //print_r(array_keys($_POST)); //abort(500, 'sadfds'); $fields = Object::getFields($id)->get(); foreach ($fields as $field) { foreach (array_keys($_POST) as $key) { if (substr($key, 0, 7) == '_field_') { $value = $request->input($key); if ($value == 'on') { $value = 1; } $object->setValue($key, $value); } } } $promoted = $request->input('_field_french_speakers'); if (!empty($promoted)) { $object->setValue('_field_french_speakers', 1); } else { $object->setValue('_field_french_speakers', 0); } $promoted = $request->input('_field_promoted'); if (!empty($promoted)) { $object->setValue('_field_promoted', 1); } else { $object->setValue('_field_promoted', 0); } if ($request->hasFile('featuredImage')) { $file = $request->file('featuredImage'); $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $mimeType = $file->getMimeType(); $destinationPath = public_path() . '/uploads/'; $newfileName = sha1($filename . time()); $picture = $newfileName . '.' . $extension; $request->file('featuredImage')->move($destinationPath, $picture); if ($imageObject = addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, '_featured_image')) { } } if ($request->hasFile('contentImage')) { $file = $request->file('contentImage'); $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $mimeType = $file->getMimeType(); $destinationPath = public_path() . '/uploads/'; $newfileName = sha1($filename . time()); $picture = $newfileName . '.' . $extension; $request->file('contentImage')->move($destinationPath, $picture); if ($imageObject = addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, '_content_image')) { } } return redirect('admin/objects')->with('message', 'Type saved successfully'); }