Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. public function update(Request $request, $id)
  2. {
  3. $this->validate($request, [
  4. 'title' => 'required',
  5. 'body' => 'required'
  6. ]);
  7.  
  8. $post = Post::find($id); // We could use this here because it's declared on top (Post model)
  9. $post->title = $request->input('title');
  10. $post->body = $request->input('body');
  11. $post->user_id = auth()->user()->id;
  12. $post->save();
  13.  
  14. return redirect('/posts')->with('success', 'Post Updated');
  15. }
  16.  
  17. @extends('layouts.app')
  18.  
  19. @section('content')
  20. <h1>Create Post</h1>
  21. {!! Form::open(['action' => 'PostsController@store', 'method' => 'POST']) !!}
  22. <div class="form-group">
  23. {{Form::label('title', 'Title')}}
  24. {{Form::text('title', '', ['class' => 'form-control', 'placeholder' => 'Title'])}}
  25. </div>
  26.  
  27. <div class="form-group">
  28. {{Form::label('body', 'Body')}}
  29. {{Form::textarea('body', '', ['id' => 'article-ckeditor', 'class' => 'form-control', 'placeholder' => 'Body Text'])}}
  30. </div>
  31. {{Form::submit('Submit', ['class' => 'btn btn-primary'])}}
  32. {!! Form::close() !!}
  33. @endsection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement