Creo que termine con el admin del post

This commit is contained in:
Daniel Cortés
2019-06-23 20:12:37 -04:00
parent 8753ad62e7
commit 08f6e9a0ab
8 changed files with 82 additions and 12 deletions

View File

@@ -14,6 +14,6 @@ class AdminController extends Controller
public function posts()
{
return view('admin.posts.index', ['posts' => Post::all()]);
return view('admin.posts.index', ['posts' => Post::orderBy('created_at', 'desc')->get()]);
}
}

View File

@@ -24,13 +24,24 @@ class PostController extends Controller
public function edit($id)
{
return view('admin.posts.edit', ['post' => Post::find($id)]);
}
public function update($id)
public function update(Request $request, $id)
{
$post = Post::find($id);
$post->title = $request->title;
$post->md = $request->md;
$post->update();
return redirect()->route('admin.post.index');
}
public function delete($id)
{
$post = Post::find($id);
$post->delete();
return redirect()->route('admin.post.index');
}
}

24
public/css/admin.css vendored
View File

@@ -93,14 +93,28 @@ table th {
text-align: left;
}
table td.controls a {
table td.controls a,
table td.controls input[type=submit] {
margin: 0;
border: 0;
padding: 0;
width: 100%;
display: block;
text-transform: uppercase;
font-weight: bold;
text-align: left;
font-size: 1rem;
font-weight: 600;
text-decoration: none;
letter-spacing: 0.1em;
color: #212121;
}
table td.controls input[type=submit] {
border: 0;
background-color: white;
cursor: pointer;
}
table th.controls a {
display: block;
text-transform: uppercase;
@@ -118,6 +132,7 @@ form label {
text-transform: uppercase;
font-weight: bold;
font-size: 0.9em;
margin-bottom: 0.6em;
}
form input[type=text],
@@ -130,14 +145,17 @@ form textarea {
border-radius: 4px;
margin-bottom: 1em;
padding: 0.4em;
font-size: 1rem;
font-weight: 400;
}
form textarea {
font-family: inherit;
box-sizing: border-box;
height: 30em;
}
form input[type=submit] {
form .button {
display: inline-block;
box-sizing: border-box;
text-align: center;

View File

@@ -94,13 +94,27 @@ table {
}
td.controls {
a {
a, input[type=submit]{
margin: 0;
border: 0;
padding: 0;
width: 100%;
display:block;
text-transform: uppercase;
font-weight: bold;
text-align: left;
font-size: 1rem;
font-weight: 600;
text-decoration: none;
letter-spacing: .1em;
color: $colorfg;
}
input[type=submit] {
border: 0;
background-color: white;
cursor: pointer;
}
}
th.controls {
@@ -122,6 +136,7 @@ form {
text-transform: uppercase;
font-weight: bold;
font-size: .9em;
margin-bottom: .6em;
}
input[type=text], textarea{
@@ -133,15 +148,18 @@ form {
border-radius: 4px;
margin-bottom: 1em;
padding: .4em;
font-size: 1rem;
font-weight: 400;
}
textarea {
font-family: inherit;
box-sizing: border-box;
height: 30em;
}
input[type=submit]{
.button{
display: inline-block;
box-sizing: border-box;
text-align: center;

View File

@@ -15,7 +15,7 @@
<label for="md">Contenido</label>
<textarea id="md" name="md"></textarea>
</div>
<input type="submit" value="Crear"/>
<input type="submit" class="button" value="Crear"/>
</form>
@endsection

View File

@@ -0,0 +1,20 @@
@extends('admin.base')
@section('title')
<h1>Edit Post</h1>
@endsection
@section('content')
<form action="{{ route('admin.post.update', ['post' => $post->id]) }}" method="post">
@csrf
<div>
<label for="title">Titulo</label>
<input type="text" id="title" name="title" value="{{ old('title', $post->title) }}" required/>
</div>
<div>
<label for="md">Contenido</label>
<textarea id="md" name="md">{{ old('md', $post->md) }}</textarea>
</div>
<input type="submit" class="button" value="Actualizar"/>
</form>
@endsection

View File

@@ -21,8 +21,11 @@
<td>{{$post->title}}</td>
<td>{{$post->created_at->format('Y-m-d')}}</td>
<td class="controls">
<a href="#">edit</a>
<a href="#">delete</a>
<a href="{{ route('admin.post.edit', ['post' => $post->id]) }}">edit</a>
<form action={{ route('admin.post.delete', ['post' => $post->id]) }} method="post">
@csrf
<input type="submit" value="delete"/>
</form>
</td>
</tr>
@endforeach

View File

@@ -23,7 +23,7 @@ Route::middleware('auth')->group(function() {
Route::post('create', 'PostController@save')->name('admin.post.save');
Route::get('{post}/edit', 'PostController@edit')->name('admin.post.edit');
Route::post('{post}/edit', 'PostController@update')->name('admin.post.update');
Route::post('{post}/delete', 'PostController@edit')->name('admin.post.delete');
Route::post('{post}/delete', 'PostController@delete')->name('admin.post.delete');
});
});
});