public function add() { $user = new Topic(); $user->user_id = '123'; $user->save(); //$results = DB::table('topic')->get(); // $results = Topic::create(['u_id'=>'103621']); // return view('m_wc.index'); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $topic = new Topic($request->all()); if ($topic->save()) { return $topic; } else { return $errors; } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(TopicRequest $request) { $topic = new Topic(); $topic->title = $request->input('title'); $topic->content = $request->input('content'); $topic->user_id = $request->user()->id; $topic->save(); return Redirect::action('TopicController@index'); }
/** * Store the topic * * @param Request $request * @return Response */ public function store(Request $request) { $this->validate($request, ['title' => 'required|max:128|min:12', 'body' => 'required|min:32', 'category' => 'required|exists:category,id'], ['title.*' => 'หัวข้อต้องมีความยาว 12-128 ตัวอักษร', 'body.*' => 'เนื้อหาต้องมีความยาวไม่น้อยกว่า 32 ตัวอักษร', 'category.*' => 'กรุณาเลือกหมวดหมู่ด้วย']); $topic = new App\Topic(); $topic->title = $request->title; $topic->body = clean($request->body); $topic->user_id = $request->user()->id; $topic->category_id = $request->category; $topic->save(); return redirect()->action('TopicController@show', ['id' => $topic->id]); }
public function store(Request $request, $lecture_id, $subject_id) { $this->validate($request, ['title' => 'required', 'description' => 'required']); $subject = Subject::find($subject_id); Log::info('$subject_id: ' . $subject->title); $topic = new Topic(); $topic->title = $request->title; $topic->description = $request->description; $topic->topic_content = $request->topic_content; $topic->subject()->associate($subject); $topic->save(); return redirect('/lectures/' . $lecture_id . '/subjects/' . $subject_id . '/topics'); }
/** * Run the database seeds. * * @return void */ public function run() { // $topics = ['Idea Generation', 'Naming', 'Domain names', 'Hosting', 'Market research', 'Forms and Surveys', 'Mockups and Wireframing', 'Design', 'Development', 'Bootcamps', 'Incubaters and Accelerators', 'Deployment', 'Social tools', 'MVP', 'Marketing', 'Early Users', 'Presentations', 'Product Demo', 'Launching', 'Analytics', 'Mobile Analytics', 'Customer Support', 'Project Management', 'Collaboration and Communication', 'Productivity', 'Bugtracking and Feedback', 'Shop', 'Payments', 'Outsourcing', 'Raising Capital', 'Investors', 'Sales', 'CRM', 'Legal', 'Finance', 'HR', 'Learning', 'Books', 'Videos', 'Articles', 'Blogs', 'Newsletters']; foreach ($topics as $topic) { $t = new Topic(); if ($t->validate(['name' => $topic])) { $t->name = $topic; if ($t->save()) { $this->command->info("Added topic: {$topic}"); } } else { $this->command->info($t->errors()); } // Topic::create(["name" => $topic]); } }
public function addTopic() { Input::merge(array_map('trim', Input::all())); $pageslug = Input::get('pageslug'); $coremenu = Menu::where('slug', $pageslug)->first(); if ($coremenu->exists()) { $level = (int) Input::get('level'); $parent = Input::get('id'); $name = Input::get('val'); $mn = new Topic(); $mn->menu_id = $coremenu->id; $mn->title = ucwords($name); $mn->parent = $parent; $mn->level = $level; $mn->save(); } return 1; }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $token = JWTAuth::getToken(); $user = JWTAuth::toUser($token); $validator = Validator::make($request->all(), ['title' => 'required|max:255', 'content' => 'required']); if ($validator->fails()) { return response()->json(['errors' => $validator->errors()], 400); } $topic = new Topic(); $topic->title = $request->title; $topic->user()->associate($user); $topic->save(); $post = new Post(); $post->content = $request->content; $post->topic()->associate($topic); $post->user()->associate($user); $post->save(); return response()->json(['topic' => $topic, 'post' => $post], 201); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //Default for number of images in the post $num_img = 0; $locationID = null; $taglist = null; if (Auth::user()->uuid) { if ($request->data) { $json = $request->data; $topicUUID = rand(0, 10) . str_random(12) . rand(0, 10); $topicSlug = str_slug($json['title'], "-") . '-' . $topicUUID; //Reviews if ($json['reviews'] != 'false') { $count = 0; foreach ($json['reviews'] as $review) { //there is a bug that says name is empty sometime if (!empty($review['name'])) { $review_data[$count] = array('topic_uuid' => $topicUUID, 'user_uuid' => Auth::user()->uuid, 'criteria' => $review['name'], 'scores' => $review['rating'], 'is_template' => TRUE, 'created_at' => date("Y-m-d H:i:s")); $count++; } } Reviews::insert($review_data); } //Location if (!empty($json['location'])) { $locationID = $json['location']['id']; //Check location exists, if not create $location_exist = DB::table('locations')->where('external_id', $locationID)->count(); if ($location_exist == 0) { $location = new Location(); $location->source = 'facebook'; //hardcode for now $location->external_id = $locationID; $location->name = $json['location']['name']; $location->category = !empty($json['location']['category']) ? $json['location']['category'] : null; $location->street = !empty($json['location']['location']['street']) ? $json['location']['location']['street'] : null; $location->city = !empty($json['location']['location']['city']) ? $json['location']['location']['city'] : null; $location->state = !empty($json['location']['location']['state']) ? $json['location']['location']['state'] : null; $location->country = !empty($json['location']['location']['country']) ? $json['location']['location']['country'] : null; $location->zip = !empty($json['location']['location']['zip']) ? $json['location']['location']['zip'] : null; $location->latitude = $json['location']['location']['latitude']; $location->longitude = $json['location']['location']['longitude']; $location->save(); } //GEt the ID } //Tag list - to store in the topic table if (!empty($json['tags'])) { $taglist = implode(",", $json['tags']); } //Images if (!empty($json['images'])) { $count = 0; //Insert images in another table foreach ($json['images'] as $image) { $img_data[$count] = array('topic_uuid' => $topicUUID, 'user_uuid' => Auth::user()->uuid, 'filename' => $image, 'created_at' => date("Y-m-d H:i:s")); $count++; } $num_img = $count; TopicImages::insert($img_data); } $topic = new Topic(); $topic->uuid = $topicUUID; $topic->type = $json['type']; $topic->uid = Auth::user()->uuid; $topic->topic = clean($json['title']); $topic->body = preg_replace('/(<[^>]+) style=".*?"/i', '$1', clean($json['body'])); $topic->text = clean($json['text']); $topic->category = $json['categories']; $topic->slug = $topicSlug; $topic->num_img = $num_img; $topic->tags = $taglist; $topic->location_id = $locationID; $topic->save(); $tag_data = array(); $count = 0; //Tags - to store in tags table if (!empty($json['tags'])) { //Insert tags in another table foreach ($json['tags'] as $tag) { Redis::zadd('post:tag' . $tag, $topic->uuid, $topic->uuid); Redis::sadd('post:' . $topic->uuid . ':tags', $tag); //Master link of tags Redis::sadd('post:tags', $tag); $tag_data[$count] = array('topic_uuid' => $topicUUID, 'title' => clean($tag), 'created_at' => date("Y-m-d H:i:s")); $count++; } Tags::insert($tag_data); } $topicEvents = Topic::find($topic->id); event(new \App\Events\TopicPostEvent($topicEvents)); $data = array("slug" => $topicSlug, "author" => Auth::user()->displayname, "type" => $json['type'], "topic_uuid" => $topicUUID); return $data; } } else { return "not login"; } }
private function uploadImage(Request $request, Topic $topic) { if (!$request->hasFile('image')) { return; } $file = $request->file('image'); $ext = $file->getClientOriginalExtension(); $name = md5($topic->title) . '.' . $ext; $file->move('uploads/topics', $name); Image::make('uploads/topics/' . $name)->fit(400, 300)->save(); $topic->image = $name; $topic->save(); }
public function topic(Request $request) { $topic = new Topic(); $topic->name = $request->name; $topic->description = $request->description; $image_name = uploadFileToS3($request, 'avatar', 300, $topic->avatar_url); if ($image_name != null) { $topic->avatar_name = $image_name; $topic->avatar_url = $this->s3_url . $image_name; } $topic->class_id = $request->class_id; $topic->author_id = $this->user->id; $topic->deadline = $request->deadline; $topic->save(); $class = StudyClass::find($request->class_id); foreach ($class->registers as $register) { $notification = new Notification(); $notification->actor_id = $this->user->id; $notification->product_id = $topic->id; $notification->receiver_id = $register->user->id; $notification->type = 5; $notification->save(); $data = array("message" => "Lớp " . $class->name . ": " . $this->user->name . " vừa tạo một topic mới ", "link" => url('group/class/' . $request->class_id . '#/topic/' . $topic->id), 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id); $publish_data = array("event" => "notification", "data" => $data); Redis::publish('colorme-channel', json_encode($publish_data)); } return response()->json($topic, 200); }