Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. @extends('layouts.app')
  2.  
  3. @section('content')
  4. <div class="container">
  5. <form action="/p" enctype="multipart/form-data" method="post">
  6. @csrf
  7.  
  8. <div class="row">
  9. <div class="col-8 offset-2">
  10.  
  11. <div class="row">
  12. <h1>Add New Post</h1>
  13. </div>
  14. <div class="form-group row">
  15. <label for="caption" class="col-md-4 col-form-label">Post Caption</label>
  16.  
  17. <input id="caption"
  18. type="text"
  19. class="form-control{{ $errors->has('caption') ? ' is-invalid' : '' }}"
  20. name="caption"
  21. value="{{ old('caption') }}"
  22. autocomplete="caption" autofocus>
  23.  
  24. @if ($errors->has('caption'))
  25. <span class="invalid-feedback" role="alert">
  26. <strong>{{ $errors->first('caption') }}</strong>
  27. </span>
  28. @endif
  29. </div>
  30.  
  31. <div class="row">
  32. <label for="image" class="col-md-4 col-form-label">Post Image</label>
  33.  
  34. <input type="file" class="form-control-file" id="image" name="image">
  35.  
  36. @if ($errors->has('image'))
  37. <strong>{{ $errors->first('image') }}</strong>
  38. @endif
  39. </div>
  40.  
  41. <div class="row pt-4">
  42. <button class="btn btn-primary">Add New Post</button>
  43. </div>
  44.  
  45. </div>
  46. </div>
  47. </form>
  48. </div>
  49. @endsection
  50.  
  51. <?php
  52.  
  53. namespace AppHttpControllers;
  54.  
  55. use IlluminateHttpRequest;
  56.  
  57. class PostsController extends Controller
  58. {
  59. public function create(){
  60. return view('posts.create');
  61. }
  62.  
  63. public function store(){
  64. $data = request()->validate([
  65. 'caption' => 'required',
  66. 'image' => ['required', 'image'],
  67. ]);
  68.  
  69. Post::create($data);
  70.  
  71. dd(request()->all());
  72. }
  73. }
  74.  
  75. <?php
  76.  
  77. /*
  78. |--------------------------------------------------------------------------
  79. | Web Routes
  80. |--------------------------------------------------------------------------
  81. |
  82. | Here is where you can register web routes for your application. These
  83. | routes are loaded by the RouteServiceProvider within a group which
  84. | contains the "web" middleware group. Now create something great!
  85. |
  86. */
  87.  
  88. Route::get('/', function () {
  89. return view('welcome');
  90. });
  91.  
  92. Auth::routes();
  93.  
  94. Route::get('/p/create', 'PostsController@create');
  95. Route::post('/p', 'PostsController@create');
  96.  
  97. Route::get('/profile/{user}', 'ProfilesController@index')->name('profile.show');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement