public function show(Tag $tag) { $posts = Tag::find($tag->id)->posts()->latest()->get(); $title = Lang::get('tags.index.title', ['tag' => $tag->name]); $header = Lang::get('tags.index.header', ['tag' => $tag->name]); return view('posts.index', compact('posts', 'title', 'header')); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(TagRequest $request, $id) { $tag = Tag::find($id); $tag->fill($request->all()); $tag->save(); Session::flash('message', 'Tag Actualizado Correctamente'); return Redirect::to('tag'); }
/** * 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); } } }