Inheritance: extends Illuminate\Database\Eloquent\Model
コード例 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  CreatePostRequest $request
  * @return Response
  */
 public function store(CreatePostRequest $request, $category_id)
 {
     // save post
     $post = new Post();
     $post->fill($request->all());
     $post->category_id = $category_id;
     $post->save();
     // if have attachment, create the attachment record
     if ($request->hasFile('attachment')) {
         // generate filename based on UUID
         $filename = Uuid::generate();
         $extension = $request->file('attachment')->getClientOriginalExtension();
         $fullfilename = $filename . '.' . $extension;
         // store the file
         Image::make($request->file('attachment')->getRealPath())->resize(null, 640, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->save(public_path() . '/attachments/' . $fullfilename);
         // attachment record
         $attachment = new Attachment();
         $attachment->post_id = $post->id;
         $attachment->original_filename = $request->file('attachment')->getClientOriginalName();
         $attachment->filename = $fullfilename;
         $attachment->mime = $request->file('attachment')->getMimeType();
         $attachment->save();
     }
     return redirect('category/' . $category_id . '/posts');
 }
コード例 #2
0
ファイル: Post.php プロジェクト: harmjanhaisma/clearboard
 /**
  * Create a new post
  * @param string $body Content of post, will be run through filters
  * @param integer $threadid Thread ID
  * @param integer| $posterid Poster's ID. Defaults to currently authenticated user
  * @param bool|false $hidden Is the post hidden from normal view?
  * @param bool|true $save Should the post be automatically saved into the database?
  * @return Post The resulting post object
  */
 public static function newPost($body, $threadid, $posterid = null, $hidden = false, $save = true)
 {
     // Check users rights
     if (!Auth::check() && $posterid === null) {
         abort(403);
         // 403 Forbidden
     }
     // Check thread
     $thread = Thread::findOrFail($threadid);
     if ($thread->locked) {
         abort(403);
         // 403 Forbidden
     }
     // Run post through filters
     $body = PostProcessor::preProcess($body);
     // Create new post
     $post = new Post();
     $post->thread_id = $threadid;
     $post->poster_id = Auth::user()->id;
     $post->body = $body;
     $post->hidden = $hidden;
     // defaults to false
     // Put post into database
     if ($save) {
         $post->save();
     }
     return $post;
 }
コード例 #3
0
 public function store(PostsRequest $request)
 {
     $post = new Post();
     $post->title = $request->input('title');
     $post->content = $request->input('content');
     $post->save();
 }
コード例 #4
0
ファイル: PostRepository.php プロジェクト: lolzballs/website
 /**
  * Remove given category from given post.
  *
  * @param Post $post
  * @param Category $category
  * @return void
  * @throws NotFoundHttpException
  */
 public function removeCategory(Post $post, Category $category)
 {
     if (!$post->categories->contains($category->id)) {
         throw new NotFoundHttpException("Category doesn't exist on Post #" . $post->id);
     }
     $post->categories()->detach($category->id);
 }
コード例 #5
0
 /**
  * API to store a new reply
  */
 public function apiStoreReply(ReplyRequest $request, Post $post)
 {
     logThis(auth()->user()->name . ' replied to ' . $post->title);
     $request->merge(['user_id' => auth()->user()->id]);
     $reply = $post->replies()->create($request->all());
     return $reply;
 }
コード例 #6
0
 public function store(Request $request)
 {
     $post = new Post();
     $post->title = $request->title;
     $post->body = $request->body;
     $post->save();
 }
コード例 #7
0
 public function postAddContent()
 {
     $url = Input::get('url');
     if (strpos($url, 'youtube.com/watch?v=') !== FALSE) {
         $type = 'youtube';
         $pieces = explode("v=", $url);
         $mediaId = $pieces[1];
     } else {
         if (strpos($url, 'vimeo.com/channels/') !== FALSE) {
             $type = 'vimeo';
             $pieces = explode("/", $url);
             $mediaId = $pieces[5];
         } else {
             if (strpos($url, 'soundcloud.com/') !== FALSE) {
                 $type = 'soundcloud';
                 $mediaId = 'null';
             } else {
                 $type = 'other';
                 $mediaId = 'null';
             }
         }
     }
     $userId = Auth::id();
     $post = new Post();
     $post->url = $url;
     $post->type = $type;
     $post->userId = $userId;
     $post->mediaId = $mediaId;
     $post->save();
     return redirect('/content')->with('success', 'Post successfully created!');
 }
コード例 #8
0
ファイル: VoteController.php プロジェクト: enhive/vev
 public function destroy(Post $post)
 {
     $vote = Vote::where(['post_id' => $post->id, 'user_id' => Auth::user()->id])->first();
     $vote->delete();
     $post->decrement('vote_count');
     return response([]);
 }
コード例 #9
0
 public function create($name, $title)
 {
     $post = new Post();
     $post->name = $name;
     $post->title = $title;
     $post->save();
     return $post;
 }
コード例 #10
0
ファイル: CommentController.php プロジェクト: enhive/vev
 public function store(Request $request, Post $post)
 {
     $comment = Comment::create($request->all());
     $post->comments()->save($comment);
     Score::create(['user_id' => Auth::user()->id, 'reference' => 'comment', 'score' => 2]);
     Auth::user()->increment('scores', 2);
     return redirect()->to('posts/' . $post->slug);
 }
コード例 #11
0
ファイル: StorePost.php プロジェクト: pastoralbanojr/BlogNow
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $post = new Post();
     $post->user_id = $this->user_id;
     $post->title = $this->title;
     $post->message = $this->message;
     $post->save();
 }
コード例 #12
0
 public function destroy(Post $post)
 {
     if ($post->image && \File::exists(public_path() . "/" . $post->image)) {
         \File::delete(public_path() . "/" . $post->image);
     }
     $post->delete();
     return redirect()->route("backend.post.index");
 }
コード例 #13
0
 public function create(Request $request)
 {
     $this->validate($request, ['name' => 'required', 'topic' => 'required']);
     $post = new Post();
     $post->name = $request->input('name');
     $post->topic = $request->input('topic');
     $post->save();
     return response()->success(compact('post'));
 }
 public function addNewPost()
 {
     $title = Input::get("title");
     $body = Input::get("body");
     $importer_id = Auth::user()['attributes']['id'];
     $v = new Post();
     $v->title = $title;
     $v->body = $body;
     $v->importer_id = $importer_id;
     $v->save();
 }
コード例 #15
0
 public function changeStatus(Post $post)
 {
     if ($post->status == 1) {
         $post->update(['status' => 0]);
         Flash::success(trans('admin/messages.postBan'));
     } elseif ($post->status == 0) {
         $post->update(['status' => 1]);
         Flash::success(trans('admin/messages.postActivate'));
     }
     return redirect()->back();
 }
コード例 #16
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(CreatePostRequest $request, Post $post)
 {
     if (Auth::user()) {
         $post = new Post($request->all());
         Auth::user()->posts()->save($post);
     } else {
         $post = new Post();
         $post->create($request->all());
     }
     return redirect()->back()->with(['success' => 'Post cadastrado com sucesso!']);
 }
コード例 #17
0
ファイル: PostController.php プロジェクト: Jimbol4/blog
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request\PostRequest  $request
  * @return \Illuminate\Http\Response
  */
 public function store(PostRequest $request)
 {
     $post = new Post();
     $post->title = $request->get('title');
     $post->text = $request->get('text');
     $post->abstract = $post->getAbstract($request->get('text'));
     $post->user_id = Auth::user()->id;
     $post->save();
     Flash::success('New post successfully created');
     return redirect('posts');
 }
コード例 #18
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     //Creating post with all post data
     $post = new Post($this->post);
     //Associating one post with one user
     // Post->belongsTo User-> associate
     $post->user()->associate($this->user);
     $post->save();
     //Attaching tags
     $post->tags()->attach($this->tags);
 }
コード例 #19
0
ファイル: BlogController.php プロジェクト: xenodus/lco_proj
 public function newPostSubmit(Request $request)
 {
     $user = Auth::user();
     $this->validate($request, ['title' => 'required|min:10', 'post_content' => 'required|min:100']);
     $post = new App\Post();
     $post->user_id = $user->id;
     $post->title = $request->title;
     $post->content = $request->post_content;
     $post->save();
     return redirect()->route('blogManager')->with('status', 'Post created!');
 }
コード例 #20
0
ファイル: TestCase.php プロジェクト: captainblue2013/Lumen
 protected function makePost($user = null)
 {
     if ($user == null) {
         $user = $this->makeUser();
     }
     $post = new Post();
     $post->content = $this->fake->sentences(10);
     $post->user()->associate($user);
     $post->save();
     return $post;
 }
コード例 #21
0
 public function updatePost(Post $post, array $postInfo)
 {
     echo 'Updating post ' . $postInfo['slug'], PHP_EOL;
     $post->content = $postInfo['content'];
     $post->description = $postInfo['description'];
     $post->slug = $postInfo['slug'];
     $post->title = $postInfo['title'];
     $post->created_at = $postInfo['created_at'];
     $post->post_dificulty_id = $postInfo['dificulty_level'];
     $post->hash = $postInfo['hash'];
     $post->save();
 }
コード例 #22
0
ファイル: PostController.php プロジェクト: jucet/larablog
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     // form inputs need to be validated
     $this->validate($request, array('title' => 'required|max:255', 'body' => 'required'));
     // store the data in the db (only if previous step was successfull)
     $post = new Post();
     $post->title = $request->title;
     $post->body = $request->body;
     $post->save();
     // (if previous step successfull) redirect to another page
     // $post->id passes the newly created id to the show view
     return redirect()->route('posts.show', $post->id);
 }
コード例 #23
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call(UserTableSeeder::class);
     $user1 = new User();
     $user1->name = "Sheryl";
     $user1->save();
     $user2 = new User();
     $user2->name = "Sherry";
     $user2->save();
     $user3 = new User();
     $user3->name = "Hilary";
     $user3->save();
     $phone1 = new Phone();
     $phone1->number = '434524';
     $phone1->user_id = 1;
     $phone1->save();
     $phone2 = new Phone();
     $phone2->number = '434524';
     $phone2->user_id = 2;
     $phone2->save();
     $post1 = new Post();
     $post1->content = 'post 1';
     $post1->user_id = 1;
     $post1->save();
     $post2 = new Post();
     $post2->content = 'post 2';
     $post2->user_id = 1;
     $post2->save();
     $post3 = new Post();
     $post3->content = 'post 3';
     $post3->user_id = 2;
     $post3->save();
     $post4 = new Post();
     $post4->user_id = 1;
     $post4->save();
     $post5 = new Post();
     $post5->content = '';
     $post5->user_id = 1;
     $post5->save();
     $photo = new Photo();
     $photo->desc = 'photo 1';
     $user1->photo()->save($photo);
     $photo = new Photo();
     $photo->desc = 'photo 2';
     $phone1->photos()->save($photo);
     $photo = new Photo();
     $photo->desc = 'photo 3';
     $phone1->photos()->save($photo);
     Model::reguard();
 }
コード例 #24
0
 public function create(Request $req)
 {
     if ($req->isMethod('post')) {
         $fields = [];
         foreach ($req->all() as $k => $v) {
             $fields[$k] = $v;
         }
         unset($fields['_token']);
         $p = new Post();
         $p->create($fields);
         return view('post.post', ['posts' => Post::all()]);
     }
     return view('post.new');
 }
コード例 #25
0
ファイル: PostController.php プロジェクト: jsnulla/test_blog
 public function store(Request $request)
 {
     try {
         $userId = \Session::get('omb_user_id');
         $post = new Post();
         $post->title = $request->postTitle;
         $post->content = $request->postContent;
         $post->user_id = $userId;
         $post->save();
         return redirect('/')->with('notify', 'Your content was posted!');
     } catch (PDOException $err) {
         return redirect()->back()->with('error', 'Your content content cannot be posted. Please try again later.');
     }
 }
コード例 #26
0
 public function store()
 {
     $rules = ['text' => 'required'];
     $input = $_POST;
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return $this->respondWithFailedValidation($validator);
     }
     $post = new Post();
     $post->content = $input['content'];
     $post->user()->associate(Auth::user());
     $post->save();
     return $this->show($post->id);
 }
コード例 #27
0
ファイル: ThreadsController.php プロジェクト: Kehet/k-forum
 /**
  * Store a newly created resource in storage.
  *
  * @param $categoryId
  * @param PostRequest $request
  * @return Response
  */
 public function store($categoryId, PostRequest $request)
 {
     if (!Sentinel::getUser()->hasAccess(['threads.create'])) {
         abort(401);
     }
     $category = Category::findOrFail($categoryId);
     $thread = new Thread();
     $thread->category_id = $category->id;
     $thread->save();
     $post = new Post($request->all());
     $post->user_id = Sentinel::getUser()->id;
     $post->thread_id = $thread->id;
     $post->save();
     return redirect()->route('categories.threads.posts.index', [$category->id, $thread->id]);
 }
コード例 #28
0
ファイル: PostController.php プロジェクト: kohrVid/L5Beauty
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $post = Post::findOrFail($id);
     $post->tags()->detach();
     $post->delete();
     return redirect()->routes("admin.post.index")->withSuccess("Post deleted.");
 }
コード例 #29
0
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('posts', function (Blueprint $table) {
         $table->boolean('body_rtl')->nullable()->default(null)->after('body_html');
     });
     Post::where(DB::raw('1=1'))->update(['body_parsed' => null, 'body_parsed_at' => null, 'body_html' => null]);
 }
コード例 #30
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $field = new StdClass();
     $field->type = "text";
     $field->name = "indredient1";
     $field->title = "Ingredient 1";
     $field->description = "Dit is de omschrijving";
     $field->validation = "required";
     $field->value = "Appels";
     $field1 = new StdClass();
     $field1->type = "textarea";
     $field1->name = "indredient2";
     $field1->title = "Indredient 2";
     $field1->description = "Dit is de omschrijving";
     $field1->validation = "required";
     $field1->value = "Bloem";
     $field2 = new StdClass();
     $field2->type = "hidden";
     $field2->name = "indredient3";
     $field2->title = "Indredient 3";
     $field2->description = "Dit is de omschrijving";
     $field2->validation = "required";
     $field2->value = "Kaneel";
     $data = array('indredient1' => $field, 'indredient2' => $field1, 'indredient3' => $field2);
     Post::create(["title" => "Appeltaart bakken", "content" => "Het meest eenvoudige appeltaart recept blijft het lekkerst. Dat gaat zeker op voor dit authentieke appeltaart recept van Koopmans. Met dit eenvoudige appeltaart recept maak je gemakkelijk deze Oudhollandse traktatie. Daar hoef je geen keukenprins of keukenprinses voor te zijn (maar dat mag natuurlijk wel). Volg het appeltaart recept op de achterkant en binnen twee uur heb je een heerlijke appeltaart op tafel staan. Ideaal als traktatie tijdens een verjaardagsfeestje voor jezelf of één van je kinderen, of gewoon zomaar, lekker bij de koffie. Met dit makkelijke appeltaart recept van Koopmans maak je iedereen blij. Jong én oud!", "url" => "appeltaart-bakken", "data" => "", "type" => "page"]);
     Post::create(["title" => "Lorem ipsum", "content" => "Lorem ipsum etc. etc.", "url" => "lorum-impsum", "data" => "", "type" => "page"]);
     Post::create(["title" => "Pagina van type Video", "content" => "Het meest eenvoudige appeltaart recept blijft het lekkerst. Dat gaat zeker op voor dit authentieke appeltaart recept van Koopmans. Met dit eenvoudige appeltaart recept maak je gemakkelijk deze Oudhollandse traktatie. Daar hoef je geen keukenprins of keukenprinses voor te zijn (maar dat mag natuurlijk wel). Volg het appeltaart recept op de achterkant en binnen twee uur heb je een heerlijke appeltaart op tafel staan. Ideaal als traktatie tijdens een verjaardagsfeestje voor jezelf of één van je kinderen, of gewoon zomaar, lekker bij de koffie. Met dit makkelijke appeltaart recept van Koopmans maak je iedereen blij. Jong én oud!", "url" => "appeltaart-bakken", "data" => "", "type" => "video"]);
     Post::create(["title" => "Post 1", "content" => "Lorem ipsum etc. etc.", "url" => "Nullam pharetra imperdiet tempor. Aliquam erat volutpat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed a dapibus augue. Donec suscipit lobortis dapibus. Nam felis tellus, finibus facilisis est ut, aliquet posuere urna. Quisque auctor quis magna ac vulputate. Etiam consequat nunc a leo elementum faucibus.", "data" => "", "type" => "post"]);
     Post::create(["title" => "Post 2", "content" => "Nullam pharetra imperdiet tempor. Aliquam erat volutpat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed a dapibus augue. Donec suscipit lobortis dapibus. Nam felis tellus, finibus facilisis est ut, aliquet posuere urna. Quisque auctor quis magna ac vulputate. Etiam consequat nunc a leo elementum faucibus.", "url" => "appeltaart-bakken", "data" => "", "type" => "post"]);
     Post::create(["title" => "Post 3", "content" => "Nullam pharetra imperdiet tempor. Aliquam erat volutpat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed a dapibus augue. Donec suscipit lobortis dapibus. Nam felis tellus, finibus facilisis est ut, aliquet posuere urna. Quisque auctor quis magna ac vulputate. Etiam consequat nunc a leo elementum faucibus.", "url" => "lorum-impsum", "data" => "", "type" => "post"]);
 }