示例#1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $category = Category::findOrFail($this->req->input('category'));
     $tags = explode(',', $this->req->input('tags'));
     $tagsCollection = Tag::lists('tag', 'id');
     $tagsToAttach = [];
     foreach ($tags as $key => $value) {
         $value = trim(ucfirst($value));
         $tag = $tagsCollection->search($value);
         if ($tag) {
             //echo $tag;
             $tagsToAttach[] = $tag;
         } else {
             $tag = new Tag();
             $tag->tag = $value;
             $tag->save();
             $tagsToAttach[] = $tag->id;
         }
     }
     $post = new Post();
     $post->title = $this->req->input('title');
     $post->user_id = Auth::user()->id;
     $post->body = $this->req->input('post');
     $category->posts()->save($post);
     $post->tags()->attach($tagsToAttach);
     return true;
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $articles = Article::paginate(5);
     $categories = Category::all();
     $tags = Tag::all();
     return view('home.index', ['articles' => $articles, 'categories' => $categories, 'tags' => $tags]);
 }
示例#3
0
 public function index()
 {
     $posts = Post::with('category', 'comments', 'tags', 'user')->orderBy('created_at', 'desc')->paginate(10);
     $latestPosts = $posts->take(5)->all();
     $categories = Category::all();
     $tags = Tag::all();
     return view('pages.home')->with(['posts' => $posts, 'latestPosts' => $latestPosts, 'categories' => $categories, 'tags' => $tags]);
 }
示例#4
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('partials.header', function ($view) {
         $view->with('pages', Page::all());
     });
     view()->composer('admin.posts.form', function ($view) {
         $view->with('tags', Tag::lists('name', 'id'));
     });
 }
 private function getTagsIds($tags)
 {
     $tagList = array_filter(array_map('trim', explode(',', $tags)));
     $tagsIDs = [];
     foreach ($tagList as $tagName) {
         $tagsIDs[] = Tag::firstOrCreate(['name' => $tagName])->id;
     }
     return $tagsIDs;
 }
示例#6
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Post::truncate();
     factory('Blog\\Post', 10)->create();
     $lastTag = count(Tag::all()) - 1;
     $posts = Post::all();
     foreach ($posts as $post) {
         # code...
         $rand = rand(0, 5);
         for ($i = 1; $i < $rand; $i++) {
             # code...
             $tag = Tag::find(rand(0, $lastTag));
             $post->tags()->attach($tag);
         }
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     Tag::truncate();
     factory(Tag::class, 10)->create();
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $article = Article::find($id);
     $categories = Category::orderBy('name', 'id')->lists('name', 'id');
     $tags = Tag::orderBy('name', 'id')->lists('name', 'id');
     $my_tags = $article->tags->lists('id')->ToArray();
     return view("article.edit", ["article" => $article, 'categories' => $categories, 'tags' => $tags, 'my_tags' => $my_tags]);
 }
示例#9
0
 public function store(CreateTagRequest $request)
 {
     return Tag::create($request->all());
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Tag::destroy($id);
     Session::flash('message', 'Tag Eliminado Correctamente');
     return Redirect::to('tag');
 }
示例#11
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($slug)
 {
     $tag = Tag::where('slug', '=', $slug)->firstorFail();
     $tag->delete();
     return redirect('admin/tag')->with('message', ['class' => 'success', 'message' => 'Tag deleted.']);
 }