コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 /**
  * 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);
     });
 }
コード例 #3
0
 /**
  * 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);
     });
 }
コード例 #4
0
 /**
  * @param $id
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function show($id)
 {
     $post = Post::findOrFail($id);
     return view('post', ['post' => $post]);
 }
コード例 #5
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $posts = Post::with('author')->get();
     return view('home', ['posts' => $posts]);
 }
コード例 #6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     return Post::delete($id);
 }