Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @extends('layouts.app')
- @section('content')
- <div class="container">
- <form action="/p" enctype="multipart/form-data" method="post">
- @csrf
- <div class="row">
- <div class="col-8 offset-2">
- <div class="row">
- <h1>Add New Post</h1>
- </div>
- <div class="form-group row">
- <label for="caption" class="col-md-4 col-form-label">Post Caption</label>
- <input id="caption"
- type="text"
- class="form-control{{ $errors->has('caption') ? ' is-invalid' : '' }}"
- name="caption"
- value="{{ old('caption') }}"
- autocomplete="caption" autofocus>
- @if ($errors->has('caption'))
- <span class="invalid-feedback" role="alert">
- <strong>{{ $errors->first('caption') }}</strong>
- </span>
- @endif
- </div>
- <div class="row">
- <label for="image" class="col-md-4 col-form-label">Post Image</label>
- <input type="file" class="form-control-file" id="image" name="image">
- @if ($errors->has('image'))
- <strong>{{ $errors->first('image') }}</strong>
- @endif
- </div>
- <div class="row pt-4">
- <button class="btn btn-primary">Add New Post</button>
- </div>
- </div>
- </div>
- </form>
- </div>
- @endsection
- <?php
- namespace AppHttpControllers;
- use IlluminateHttpRequest;
- class PostsController extends Controller
- {
- public function create(){
- return view('posts.create');
- }
- public function store(){
- $data = request()->validate([
- 'caption' => 'required',
- 'image' => ['required', 'image'],
- ]);
- Post::create($data);
- dd(request()->all());
- }
- }
- <?php
- /*
- |--------------------------------------------------------------------------
- | Web Routes
- |--------------------------------------------------------------------------
- |
- | Here is where you can register web routes for your application. These
- | routes are loaded by the RouteServiceProvider within a group which
- | contains the "web" middleware group. Now create something great!
- |
- */
- Route::get('/', function () {
- return view('welcome');
- });
- Auth::routes();
- Route::get('/p/create', 'PostsController@create');
- Route::post('/p', 'PostsController@create');
- Route::get('/profile/{user}', 'ProfilesController@index')->name('profile.show');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement