コード例 #1
0
ファイル: PostsManager.php プロジェクト: talv86/easel
 /**
  * @param $tag
  *
  * @return array
  */
 public function postsByTag($tag)
 {
     $tag = Tag::where('tag', $tag)->firstOrFail();
     $reverse_direction = (bool) $tag->reverse_direction;
     $posts = Post::where('published_at', '<=', Carbon::now())->whereHas('tags', function (Builder $q) use($tag) {
         $q->where('tag', '=', $tag->tag);
     })->where('is_draft', 0)->orderBy('published_at', $reverse_direction ? 'asc' : 'desc')->simplePaginate(config('easel.posts_per_page'));
     $posts->addQuery('tag', $tag->tag);
     return $this->assemblePostData($posts, $tag);
 }
コード例 #2
0
ファイル: BlogController.php プロジェクト: talv86/easel
 /**
  * Display the specified resource.
  *
  * @param         $slug
  * @param Request $request
  *
  * @return \Illuminate\Http\Response
  */
 public function showPost($slug, Request $request)
 {
     $post = Post::with('tags')->whereSlug($slug)->firstOrFail();
     $tag = $request->get('tag');
     $title = $post->title;
     if ($tag) {
         $tag = Tag::whereTag($tag)->firstOrFail();
     }
     $data = ['post' => $post, 'tag' => $tag, 'title' => $title];
     return view($post->layout, $data);
 }
コード例 #3
0
ファイル: PostFormFields.php プロジェクト: talv86/easel
 /**
  * Return the field values from the model.
  *
  * @param int   $id
  * @param array $fields
  *
  * @return array
  */
 protected function fieldsFromModel($id, array $fields)
 {
     $post = Post::findOrFail($id);
     $fieldNames = array_keys(array_except($fields, ['tags']));
     $fields = ['id' => $id];
     foreach ($fieldNames as $field) {
         $fields[$field] = $post->{$field};
     }
     $fields['tags'] = $post->tags()->pluck('tag')->all();
     $fields['published_at'] = $post->published_at->format('d/m/Y H:i:s');
     return $fields;
 }
コード例 #4
0
ファイル: BlogPostTest.php プロジェクト: talv86/easel
 public function test_a_post_can_be_deleted()
 {
     // Create new post
     $post = $this->createPostData();
     $post->save();
     $this->assertTrue(\Easel\Models\Post::count() === 1);
     // Delete it!
     $this->actingAs($this->user)->delete('admin/post/' . $post->id);
     // Is It There?
     $this->assertTrue(\Easel\Models\Post::count() === 0);
     $this->assertSessionHas('_delete-post', trans('easel::messages.delete_success', ['entity' => 'Post']));
     $this->assertRedirectedTo('/admin/post');
 }
コード例 #5
0
ファイル: SearchController.php プロジェクト: talv86/easel
 /**
  * Display search result.
  *
  * @return \Illuminate\View\View
  */
 public function index()
 {
     $params = request('search');
     try {
         $posts = Post::search($params)->get();
         $tags = Tag::search($params)->get();
     } catch (\Exception $e) {
         //fallback to basic search
         $posts = Post::where('title', 'LIKE', '%' . $params . '%')->orWhere('subtitle', 'LIKE', '%' . $params . '%')->orWhere('content_raw', 'LIKE', '%' . $params . '%')->orWhere('meta_description', 'LIKE', '%' . $params . '%')->get();
         $tags = Tag::where('tag', 'LIKE', '%' . $params . '%')->orWhere('title', 'LIKE', '%' . $params . '%')->orWhere('subtitle', 'LIKE', '%' . $params . '%')->orWhere('meta_description', 'LIKE', '%' . $params . '%')->get();
     }
     return view('easel::backend.search.index', compact('params', 'posts', 'tags'));
 }
コード例 #6
0
ファイル: SearchTest.php プロジェクト: talv86/easel
 public function test_can_search_posts()
 {
     //create two posts to show up and one to not show
     $postA = factory(Post::class)->make(['title' => 'here is a test title that contains the word Easel', 'slug' => 'test-slug', 'content_raw' => 'no content']);
     $postB = factory(Post::class)->make(['title' => 'easel', 'content_raw' => 'here is a test content that contains the word Easel']);
     $postC = factory(Post::class)->make(['title' => 'this shouldnt show up', 'slug' => 'this-shouldnt-show-up-slug', 'subtitle' => 'this-shouldnt-show-up', 'meta_description' => 'this-shouldnt-show-up', 'content_raw' => 'this-shouldnt-show-up']);
     $postA->save();
     $postB->save();
     $postC->save();
     $posts = Post::whereIn('id', [$postA->id, $postB->id])->get();
     //$posts    = Post::search('easel')->get();
     $response = $this->actingAs($this->user)->call('GET', '/admin/search?search=easel');
     $this->assertEquals(200, $response->status());
     $this->assertViewHas('posts', $posts);
 }
コード例 #7
0
ファイル: PostController.php プロジェクト: talv86/easel
 /**
  * Remove the specified resource from storage.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id)
 {
     /** @var Post $post */
     $post = Post::findOrFail($id);
     $post->tags()->detach();
     $post->delete();
     Session::set('_delete-post', trans('easel::messages.delete_success', ['entity' => 'Post']));
     return redirect()->route('admin.post.index');
 }
コード例 #8
0
ファイル: PostTableSeeder.php プロジェクト: talv86/easel
 /**
  * Seed the posts table with the Welcome post.
  */
 public function run()
 {
     Post::truncate();
     factory(Post::class, 1)->create();
 }