update nav, fix file upload name, rename posts>postcontroller
This commit is contained in:
parent
f601abae7a
commit
66045b8792
@ -2,13 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\BlogPost;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class PostController extends Controller
|
class PostController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return view('admin.posts.index');
|
return view('admin.posts.index', [
|
||||||
|
'posts' => BlogPost::all()
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create()
|
public function create()
|
||||||
@ -18,7 +21,7 @@ public function create()
|
|||||||
|
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
dd($request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
|
24
app/Http/Requests/PostRequest.php
Normal file
24
app/Http/Requests/PostRequest.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class PostRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => ['required', 'string', 'max:255'],
|
||||||
|
'content' => ['required'],
|
||||||
|
'location' => ['nullable'],
|
||||||
|
'files' => ['nullable', 'mimes:jpg,jpeg,png', 'max:20000'],
|
||||||
|
'tags' => ['nullable'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,7 @@
|
|||||||
<h3>Create new post</h3>
|
<h3>Create new post</h3>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<form action="{{route('posts.store')}}" method="post" id="createPostForm">
|
<form action="{{route('posts.store')}}" method="post" enctype="multipart/form-data">
|
||||||
@csrf
|
@csrf
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
<label for="files" class="form-label">Upload pictures</label>
|
<label for="files" class="form-label">Upload pictures</label>
|
||||||
<input class="form-control" type="file" id="files" name="files" multiple>
|
<input class="form-control" type="file" id="files" name="files[]" multiple>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group mt-4">
|
<div class="form-group mt-4">
|
||||||
|
@ -3,6 +3,33 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="col-md-9 px-4">
|
||||||
|
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">#</th>
|
||||||
|
<th scope="col">Title</th>
|
||||||
|
<th scope="col">Date</th>
|
||||||
|
<th scope="col"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
@foreach($posts as $post)
|
||||||
|
|
||||||
|
{{-- todo: set proper href link for post entry--}}
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{{$post->id}}</th>
|
||||||
|
<td><a href="" class="text-dark">{{$post->title}}</a></td>
|
||||||
|
<td>{{$post->created_at->format("y-m-d")}}</td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||||
<a class="dropdown-item @if(request()->routeIs('posts.create')) active @endif"
|
<a class="dropdown-item @if(request()->routeIs('posts.create')) active @endif"
|
||||||
href="{{route('posts.create')}}">Create new post</a>
|
href="{{route('posts.create')}}">Create new post</a>
|
||||||
<a class="dropdown-item" href="#">All posts</a>
|
<a class="dropdown-item @if(request()->routeIs('posts.index')) active @endif"
|
||||||
|
href="{{route('posts.index')}}">Posts Index</a>
|
||||||
{{-- <div class="dropdown-divider"></div>--}}
|
{{-- <div class="dropdown-divider"></div>--}}
|
||||||
{{-- <a class="dropdown-item" href="#">Something else here</a>--}}
|
{{-- <a class="dropdown-item" href="#">Something else here</a>--}}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user