예제 #1
0
 /**
  * @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
파일: TagManager.php 프로젝트: talv86/easel
 /**
  * @param null $id
  *
  * @return array
  */
 public function getViewData($id = null)
 {
     if ($id !== null) {
         /** @var $data */
         $data = Tag::findOrFail($id)->toArray();
     } else {
         $data = $this->fields;
     }
     return array_merge($data, ['layouts' => $this->getPostLayouts()]);
 }
예제 #3
0
 /**
  * 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);
 }
예제 #4
0
파일: TagsTest.php 프로젝트: talv86/easel
 public function test_a_tag_can_be_deleted()
 {
     // Create a new Tag
     $tag = factory(Tag::class)->make();
     $tag->save();
     // Delete it!
     $this->actingAs($this->user)->delete('admin/tag/' . $tag->id);
     // Is it there?
     $this->assertTrue(Tag::count() === 0);
     $this->assertSessionHas('_delete-tag', trans('easel::messages.delete_success', ['entity' => 'Tag']));
     $this->assertRedirectedTo('/admin/tag');
 }
예제 #5
0
 /**
  * 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
 /**
  * Execute the command.
  *
  * @return array of field names => values
  */
 public function handle()
 {
     $fields = $this->fieldList;
     if ($this->id) {
         $fields = $this->fieldsFromModel($this->id, $fields);
     } else {
         $when = Carbon::now()->addHour();
         $fields['published_at'] = $when;
     }
     foreach ($fields as $fieldName => $fieldValue) {
         $fields[$fieldName] = old($fieldName, $fieldValue);
     }
     return array_merge($fields, ['allTags' => Tag::pluck('tag')->all(), 'layouts' => $this->getPostLayouts()]);
 }
예제 #7
0
파일: SearchTest.php 프로젝트: talv86/easel
 public function test_can_search_tags()
 {
     //create two tag to show up and one to not show
     $tagA = factory(Tag::class)->make(['title' => 'easel', 'tag' => 'easel']);
     $tagB = factory(Tag::class)->make(['title' => 'Easel', 'subtitle' => 'easel']);
     $tagC = factory(Tag::class)->make(['tag' => 'this shouldnt show up', 'title' => 'this-shouldnt-show-up', 'meta_description' => 'this-shouldnt-show-up', 'subtitle' => 'this-shouldnt-show-up']);
     $tagA->save();
     $tagB->save();
     $tagC->save();
     $tags = Tag::whereIn('id', [$tagA->id, $tagB->id])->get();
     //$tags     = Tag::search('easel')->get();
     $response = $this->actingAs($this->user)->call('GET', '/admin/search?search=easel');
     $this->assertEquals(200, $response->status());
     $this->assertViewHas('tags', $tags);
 }
예제 #8
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\View\View
  */
 public function index()
 {
     $data = Tag::all();
     return view('easel::backend.tag.index', compact('data'));
 }
예제 #9
0
 /**
  * Seed the tags table with the Welcome tag.
  */
 public function run()
 {
     Tag::truncate();
     factory(Tag::class, 1)->create();
 }
예제 #10
0
파일: Post.php 프로젝트: talv86/easel
 /**
  * Sync tag relationships and add new tags as needed.
  *
  * @param array $tags
  */
 public function syncTags(array $tags)
 {
     Tag::addNeededTags($tags);
     if (count($tags)) {
         $this->tags()->sync(Tag::whereIn('tag', $tags)->pluck('id')->all());
         return;
     }
     $this->tags()->detach();
 }