Inheritance: extends app\models\Model
Beispiel #1
0
 /**
  * Create post
  *
  * @param Request $request
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function create(Request $request)
 {
     if ($request->isMethod("post")) {
         $rules = ["title" => "required", "alias" => "required|unique:posts,alias", "content" => "required", 'image' => 'mimes:jpeg,jpg,png'];
         Validator::make($request->all(), $rules)->validate();
         $post = new Post();
         $post->title = $request->input("title");
         $post->alias = $request->input("alias");
         $post->content = $request->input("content");
         $post->meta_keys = $request->input("meta_keys");
         $post->meta_desc = $request->input("meta_desc");
         if (!empty($request->file("image"))) {
             $generated_string = str_random(32);
             $file = $request->file("image")->store('uploads');
             $new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension();
             Storage::move($file, 'uploads/' . $new_file);
             $img = Image::make($request->file('image'));
             $img->crop(200, 200);
             $img->save(storage_path('app/public/uploads/' . $new_file));
             $img = Image::make($request->file('image'));
             $img->resize(600, 315);
             $img->save(storage_path('app/public/uploads/fb-' . $new_file));
             $post->image = $new_file;
         }
         if ($request->has("category")) {
             $post->category_id = $request->input("category");
         }
         $post->publish = $request->has("publish");
         $post->author_id = Auth::user()->id;
         $post->save();
         if ($request->has("tags")) {
             foreach ($request->input("tags") as $tag) {
                 $post_tag = new PostTag();
                 $post_tag->post_id = $post->id;
                 $post_tag->tag_id = $tag;
                 $post_tag->save();
             }
         }
         $admins = User::getAdmins();
         foreach ($admins as $admin) {
             if ($admin->id != Auth::user()->id) {
                 $notification = new Notification();
                 $notification->from = Auth::user()->id;
                 $notification->to = $admin->id;
                 $notification->type = 3;
                 $notification->save();
             }
         }
         return redirect()->route('posts');
     } else {
         $categories = Category::getCategoriesByPublish();
         $tags = Tag::getTags();
         return view("site.post.create", compact("categories", "tags", "post"));
     }
 }
Beispiel #2
0
 public function remove($tag_id)
 {
     Tags::destroy($tag_id);
     PostTag::where(['tag_id' => $tag_id])->delete();
     Notifications::add('Tag removed', 'success');
     return Redirect::back();
 }
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();
        $lipsum = new LoremIpsumGenerator();
        Role::create(['title' => 'Administrator', 'slug' => 'admin']);
        Role::create(['title' => 'Redactor', 'slug' => 'redac']);
        Role::create(['title' => 'User', 'slug' => 'user']);
        User::create(['username' => 'GreatAdmin', 'email' => '*****@*****.**', 'password' => bcrypt('admin'), 'seen' => true, 'role_id' => 1, 'confirmed' => true]);
        User::create(['username' => 'GreatRedactor', 'email' => '*****@*****.**', 'password' => bcrypt('redac'), 'seen' => true, 'role_id' => 2, 'valid' => true, 'confirmed' => true]);
        User::create(['username' => 'Walker', 'email' => '*****@*****.**', 'password' => bcrypt('walker'), 'role_id' => 3, 'confirmed' => true]);
        User::create(['username' => 'Slacker', 'email' => '*****@*****.**', 'password' => bcrypt('slacker'), 'role_id' => 3, 'confirmed' => true]);
        Contact::create(['name' => 'Dupont', 'email' => '*****@*****.**', 'text' => 'Lorem ipsum inceptos malesuada leo fusce tortor sociosqu semper, facilisis semper class tempus faucibus tristique duis eros, cubilia quisque habitasse aliquam fringilla orci non. Vel laoreet dolor enim justo facilisis neque accumsan, in ad venenatis hac per dictumst nulla ligula, donec mollis massa porttitor ullamcorper risus. Eu platea fringilla, habitasse.']);
        Contact::create(['name' => 'Durand', 'email' => '*****@*****.**', 'text' => ' Lorem ipsum erat non elit ultrices placerat, netus metus feugiat non conubia fusce porttitor, sociosqu diam commodo metus in. Himenaeos vitae aptent consequat luctus purus eleifend enim, sollicitudin eleifend porta malesuada ac class conubia, condimentum mauris facilisis conubia quis scelerisque. Lacinia tempus nullam felis fusce ac potenti netus ornare semper molestie, iaculis fermentum ornare curabitur tincidunt imperdiet scelerisque imperdiet euismod.']);
        Contact::create(['name' => 'Martin', 'email' => '*****@*****.**', 'text' => 'Lorem ipsum tempor netus aenean ligula habitant vehicula tempor ultrices, placerat sociosqu ultrices consectetur ullamcorper tincidunt quisque tellus, ante nostra euismod nec suspendisse sem curabitur elit. Malesuada lacus viverra sagittis sit ornare orci, augue nullam adipiscing pulvinar libero aliquam vestibulum, platea cursus pellentesque leo dui. Lectus curabitur euismod ad, erat.', 'seen' => true]);
        Tag::create(['tag' => 'Tag1']);
        Tag::create(['tag' => 'Tag2']);
        Tag::create(['tag' => 'Tag3']);
        Tag::create(['tag' => 'Tag4']);
        Post::create(['title' => 'Post 1', 'slug' => 'post-1', 'summary' => '<img alt="" src="/filemanager/userfiles/user2/mega-champignon.png" style="float:left; height:128px; width:128px" />' . $lipsum->getContent(50), 'content' => $lipsum->getContent(500), 'active' => true, 'user_id' => 1]);
        Post::create(['title' => 'Post 2', 'slug' => 'post-2', 'summary' => '<img alt="" src="/filemanager/userfiles/user2/goomba.png" style="float:left; height:128px; width:128px" />' . $lipsum->getContent(50), 'content' => '<p>Lorem ipsum convallis ac curae non elit ultrices placerat netus metus feugiat, non conubia fusce porttitor sociosqu diam commodo metus in himenaeos, vitae aptent consequat luctus purus eleifend enim sollicitudin eleifend porta. Malesuada ac class conubia condimentum mauris facilisis conubia quis scelerisque lacinia, tempus nullam felis fusce ac potenti netus ornare semper. Molestie iaculis fermentum ornare curabitur tincidunt imperdiet scelerisque, imperdiet euismod scelerisque torquent curae rhoncus, sollicitudin tortor placerat aptent hac nec. Posuere suscipit sed tortor neque urna hendrerit vehicula duis litora tristique congue nec auctor felis libero, ornare habitasse nec elit felis inceptos tellus inceptos cubilia quis mattis faucibus sem non.</p>

<p>Odio fringilla class aliquam metus ipsum lorem luctus pharetra dictum, vehicula tempus in venenatis gravida ut gravida proin orci, quis sed platea mi quisque hendrerit semper hendrerit. Facilisis ante sapien faucibus ligula commodo vestibulum rutrum pretium, varius sem aliquet himenaeos dolor cursus nunc habitasse, aliquam ut curabitur ipsum luctus ut rutrum. Odio condimentum donec suscipit molestie est etiam sit rutrum dui nostra, sem aliquet conubia nullam sollicitudin rhoncus venenatis vivamus rhoncus netus, risus tortor non mauris turpis eget integer nibh dolor. Commodo venenatis ut molestie semper adipiscing amet cras, class donec sapien malesuada auctor sapien arcu inceptos, aenean consequat metus litora mattis vivamus.</p>

<pre>
<code class="language-php">protected function getUserByRecaller($recaller)
{
	if ($this-&gt;validRecaller($recaller) &amp;&amp; ! $this-&gt;tokenRetrievalAttempted)
	{
		$this-&gt;tokenRetrievalAttempted = true;

		list($id, $token) = explode("|", $recaller, 2);

		$this-&gt;viaRemember = ! is_null($user = $this-&gt;provider-&gt;retrieveByToken($id, $token));

		return $user;
	}
}</code></pre>

<p>Feugiat arcu adipiscing mauris primis ante ullamcorper ad nisi, lobortis arcu per orci malesuada blandit metus tortor, urna turpis consectetur porttitor egestas sed eleifend. Eget tincidunt pharetra varius tincidunt morbi malesuada elementum mi torquent mollis, eu lobortis curae purus amet vivamus amet nulla torquent, nibh eu diam aliquam pretium donec aliquam tempus lacus. Tempus feugiat lectus cras non velit mollis sit et integer, egestas habitant auctor integer sem at nam massa himenaeos, netus vel dapibus nibh malesuada leo fusce tortor. Sociosqu semper facilisis semper class tempus faucibus tristique duis eros, cubilia quisque habitasse aliquam fringilla orci non vel, laoreet dolor enim justo facilisis neque accumsan in.</p>

<p>Ad venenatis hac per dictumst nulla ligula donec, mollis massa porttitor ullamcorper risus eu platea, fringilla habitasse suscipit pellentesque donec est. Habitant vehicula tempor ultrices placerat sociosqu ultrices consectetur ullamcorper tincidunt quisque tellus, ante nostra euismod nec suspendisse sem curabitur elit malesuada lacus. Viverra sagittis sit ornare orci augue nullam adipiscing pulvinar libero aliquam vestibulum platea cursus pellentesque leo dui lectus, curabitur euismod ad erat curae non elit ultrices placerat netus metus feugiat non conubia fusce porttitor. Sociosqu diam commodo metus in himenaeos vitae aptent consequat luctus purus eleifend enim sollicitudin eleifend, porta malesuada ac class conubia condimentum mauris facilisis conubia quis scelerisque lacinia.</p>

<p>Tempus nullam felis fusce ac potenti netus ornare semper molestie iaculis, fermentum ornare curabitur tincidunt imperdiet scelerisque imperdiet euismod. Scelerisque torquent curae rhoncus sollicitudin tortor placerat aptent hac, nec posuere suscipit sed tortor neque urna hendrerit, vehicula duis litora tristique congue nec auctor. Felis libero ornare habitasse nec elit felis, inceptos tellus inceptos cubilia quis mattis, faucibus sem non odio fringilla. Class aliquam metus ipsum lorem luctus pharetra dictum vehicula, tempus in venenatis gravida ut gravida proin orci, quis sed platea mi quisque hendrerit semper.</p>
', 'active' => true, 'user_id' => 2]);
        Post::create(['title' => 'Post 3', 'slug' => 'post-3', 'summary' => '<img alt="" src="/filemanager/userfiles/user2/rouge-shell.png" style="float:left; height:128px; width:128px" />' . $lipsum->getContent(50), 'content' => $lipsum->getContent(500), 'active' => true, 'user_id' => 2]);
        Post::create(['title' => 'Post 4', 'slug' => 'post-4', 'summary' => '<img alt="" src="/filemanager/userfiles/user2/rouge-shyguy.png" style="float:left; height:128px; width:128px" />' . $lipsum->getContent(50), 'content' => $lipsum->getContent(500), 'active' => true, 'user_id' => 2]);
        PostTag::create(['post_id' => 1, 'tag_id' => 1]);
        PostTag::create(['post_id' => 1, 'tag_id' => 2]);
        PostTag::create(['post_id' => 2, 'tag_id' => 1]);
        PostTag::create(['post_id' => 2, 'tag_id' => 2]);
        PostTag::create(['post_id' => 2, 'tag_id' => 3]);
        PostTag::create(['post_id' => 3, 'tag_id' => 1]);
        PostTag::create(['post_id' => 3, 'tag_id' => 2]);
        PostTag::create(['post_id' => 3, 'tag_id' => 4]);
        Comment::create(['content' => $lipsum->getContent(200), 'user_id' => 2, 'post_id' => 1]);
        Comment::create(['content' => $lipsum->getContent(200), 'user_id' => 2, 'post_id' => 2]);
        Comment::create(['content' => $lipsum->getContent(200), 'user_id' => 3, 'post_id' => 1]);
    }
 public function run()
 {
     $faker = Faker::create();
     $tags = Tag::lists('id')->toArray();
     for ($i = 1; $i <= 50; $i++) {
         PostTag::create(['post_id' => $i, 'tag_id' => $faker->randomElement($tags)]);
         PostTag::create(['post_id' => $i, 'tag_id' => $faker->randomElement($tags)]);
         PostTag::create(['post_id' => $i, 'tag_id' => $faker->randomElement($tags)]);
     }
 }
Beispiel #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PostTag::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->joinWith(['post', 'tag']);
     /*$query->andFilterWhere([
           'post_id' => $this->post_id,
           'tag_id' => $this->tag_id,
       ]);*/
     $query->andFilterWhere(['like', 'post_title', $this->post_id])->andFilterWhere(['like', 'tag_name', $this->tag_id]);
     return $dataProvider;
 }
Beispiel #6
0
 private function _setTags($tags_str, $post_id)
 {
     PostTag::where('post_id', $post_id)->delete();
     $tags = explode(', ', $tags_str);
     foreach ($tags as $tag) {
         if (trim($tag) == '') {
             continue;
         }
         $tag = mb_strtolower($tag);
         $dbtag = Tags::where('tag', 'like', $tag)->first();
         if (empty($dbtag)) {
             $dbtag = new Tags();
             $dbtag->tag = strip_tags($tag);
             $dbtag->save();
         }
         $post_tag = new PostTag();
         $post_tag->post_id = $post_id;
         $post_tag->tag_id = $dbtag->id;
         $post_tag->save();
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPostTags()
 {
     return $this->hasMany(PostTag::className(), ['post_id' => 'id']);
 }
Beispiel #8
0
 public function update($postID)
 {
     $data = \Input::all();
     if (isset($data['post'])) {
         $post = Post::find($postID);
         if ($post) {
             if (isset($data['post']['title'])) {
                 $post->title = $data['post']['title'];
             }
             if (isset($data['post']['body'])) {
                 $post->body = $data['post']['body'];
             }
             if ($post->save()) {
                 if (isset($data['post']['tags'])) {
                     PostTag::where('post_id', '=', $postID)->delete();
                     $this->savePostTags($post->id, $data['post']['tags']);
                 }
                 Cache::forget('all_post');
                 //Forgot all post store in cache
                 Cache::forget('post_' . $postID);
                 //Forgot post_ID in store cache
                 return self::makeResponse(array());
             } else {
                 return self::makeResponse(array(), 500, 'Server Error');
             }
         } else {
             return self::makeResponse(array(), 404, 'Cound not found post');
         }
     } else {
         return self::makeResponse(array(), 400, 'Bad Request');
     }
 }
 /**
  * Finds the PostTag model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $post_id
  * @param integer $tag_id
  * @return PostTag the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($post_id, $tag_id)
 {
     if (($model = PostTag::findOne(['post_id' => $post_id, 'tag_id' => $tag_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }