/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $post = Post::findOrFail($id); $post->title = $request->get('title'); $post->body = $request->get('body'); $post->save(); return redirect()->route('post_show_path', $post->id); }
/** * Run the database seeds. * * @return void */ public function run() { User::truncate(); Post::truncate(); factory(PlatziPHP\User::class, 10)->create()->each(function ($user) { $post = factory(PlatziPHP\Post::class)->make(); $user->posts()->save($post); }); }
/** * Run the database seeds. * * @return void */ public function run() { // Insert Simple /*DB::table('users')->insert([ 'name' => 'Hugo', 'email' => '*****@*****.**' ]);*/ \PlatziPHP\User::truncate(); \PlatziPHP\Post::truncate(); factory(PlatziPHP\User::class, 10)->create()->each(function ($user) { $post = factory(PlatziPHP\Post::class)->make(); $user->posts()->save($post); }); }
/** * @param $id * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show($id) { $post = Post::findOrFail($id); return view('post', ['post' => $post]); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $posts = Post::with('author')->get(); return view('home', ['posts' => $posts]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { return Post::delete($id); }