Пример #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
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //Model::unguard();
     $user = new User();
     $user->name = 'Vaidas';
     $user->email = '*****@*****.**';
     $user->password = bcrypt('123456');
     $user->is_admin = 1;
     $user->save();
     $category = new Category();
     $category->slug = 'sports';
     $category->category = 'Sports';
     $category->save();
     $category = new Category();
     $category->slug = 'nature';
     $category->category = 'Nature';
     $category->save();
     $category = new Category();
     $category->slug = 'politics';
     $category->category = 'Politics';
     $category->save();
     //Model::reguard();
 }
Пример #5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($slug)
 {
     $category = Category::where('slug', '=', $slug)->firstorFail();
     $category->delete();
     return redirect('admin/category')->with('message', ['class' => 'success', 'message' => 'Category deleted.']);
 }
 /**
  * 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]);
 }
Пример #7
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($slug)
 {
     $post = Post::where('slug', '=', $slug)->firstorFail();
     $categories = Category::lists('category', 'id');
     return view('admin.post.edit')->with(['post' => $post, 'categories' => $categories]);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Category::destroy($id);
     Session::flash('message', 'Categoria Eliminada Correctamente');
     return Redirect::to('category');
 }