Estoy avanzando en el adminpanel

This commit is contained in:
Daniel Cortés
2019-06-23 18:18:35 -04:00
parent be42d6f599
commit 8753ad62e7
10 changed files with 352 additions and 40 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Post;
use Illuminate\Http\Request;
class AdminController extends Controller
@@ -10,4 +11,9 @@ class AdminController extends Controller
{
return view('admin.index');
}
public function posts()
{
return view('admin.posts.index', ['posts' => Post::all()]);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Http\Controllers;
use App\Post;
use Illuminate\Http\Request;
class PostController extends Controller
{
public function create()
{
return view('admin.posts.create');
}
public function save(Request $request)
{
$post = new Post();
$post->title = $request->title;
$post->md = $request->md;
$post->save();
return redirect()->route('admin.post.index');
}
public function edit($id)
{
}
public function update($id)
{
}
public function delete($id)
{
}
}

100
public/css/admin.css vendored
View File

@@ -3,6 +3,10 @@ body {
color: #212121;
}
hr {
border: 1px solid #f2f2f2;
}
.sidebar {
position: fixed;
left: 0;
@@ -49,13 +53,103 @@ body {
color: #0fa0ce;
}
.sidebar span {
font-size: 1.2rem;
margin: 2em 0;
.sidebar h1 {
text-align: center;
}
.container {
margin-left: 20ch;
height: 100vh;
padding: 0em 2em;
}
@media (max-width: 600px) {
.sidebar {
display: none;
}
.container {
margin-left: 0;
}
}
table {
width: 100%;
border-collapse: collapse;
}
table th {
background: #212121;
color: #f2f2f2;
font-weight: bold;
text-transform: uppercase;
}
table td,
table th {
padding: 6px;
height: 2em;
border-bottom: 1px solid #212121;
text-align: left;
}
table td.controls a {
display: block;
text-transform: uppercase;
font-weight: bold;
text-decoration: none;
color: #212121;
}
table th.controls a {
display: block;
text-transform: uppercase;
font-weight: bold;
text-decoration: none;
color: white;
}
form {
height: 100%;
}
form label {
display: block;
text-transform: uppercase;
font-weight: bold;
font-size: 0.9em;
}
form input[type=text],
form textarea {
box-sizing: border-box;
display: block;
width: 100%;
height: 2em;
border: 1px solid #212121;
border-radius: 4px;
margin-bottom: 1em;
padding: 0.4em;
}
form textarea {
box-sizing: border-box;
height: 30em;
}
form input[type=submit] {
display: inline-block;
box-sizing: border-box;
text-align: center;
cursor: pointer;
color: #212121;
border: 1px solid #212121;
border-radius: 4px;
background-color: #fff;
font-weight: bold;
height: 38px;
padding: 0 38px;
margin-bottom: 3em;
text-transform: uppercase;
}

View File

@@ -7,6 +7,10 @@ body {
color: $colorfg;
}
hr {
border: 1px solid $colorborder;
}
.sidebar {
position:fixed;
left: 0;
@@ -49,13 +53,108 @@ body {
color: $color01;
}
span {
font-size: 1.2rem;
margin: 2em 0;
h1 {
text-align:center;
}
}
.container {
margin-left: 20ch;
height:100vh;
padding: 0em 2em;
}
@media (max-width: 600px) {
.sidebar{
display: none;
}
.container{
margin-left: 0;
}
}
table {
width: 100%;
border-collapse: collapse;
th {
background: $colorfg;
color: $colorborder;
font-weight: bold;
text-transform: uppercase;
}
td, th {
padding: 6px;
height: 2em;
border-bottom: 1px solid $colorfg;
text-align: left;
}
td.controls {
a {
display:block;
text-transform: uppercase;
font-weight: bold;
text-decoration: none;
color: $colorfg;
}
}
th.controls {
a {
display:block;
text-transform: uppercase;
font-weight: bold;
text-decoration: none;
color: white;
}
}
}
form {
height: 100%;
label {
display: block;
text-transform: uppercase;
font-weight: bold;
font-size: .9em;
}
input[type=text], textarea{
box-sizing: border-box;
display: block;
width: 100%;
height: 2em;
border: 1px solid $colorfg;
border-radius: 4px;
margin-bottom: 1em;
padding: .4em;
}
textarea {
box-sizing: border-box;
height: 30em;
}
input[type=submit]{
display: inline-block;
box-sizing: border-box;
text-align: center;
cursor: pointer;
color: $colorfg;
border: 1px solid $colorfg;
border-radius: 4px;
background-color: #fff;
font-weight: bold;
height: 38px;
padding: 0 38px;
margin-bottom: 3em;
text-transform: uppercase;
}
}

View File

@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Daniel Cortés</title>
<link href="{{ asset('css/admin.css') }}" rel="stylesheet">
</head>
<body>
<div class="sidebar">
<div class="items">
<div class="head"><h1>Admin</h1></div>
<div class="item"><a href="{{ route('admin.post.index') }}">Posts</a></div>
<div class="item"><a href="#">Now</a></div>
<div class="item"><a href="#">Setup</a></div>
<div class="item"><a href="#">Projects</a></div>
<div class="end"><a href="{{ route('index') }}">Volver</a></div>
</div>
</div>
<div class="container">
@yield('title')
<hr/>
@yield('content')
</div>
<script src="js/app.js"></script>
</body>
</html>

View File

@@ -1,28 +1,9 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@extends('admin.base')
@section('title')
<title>Daniel Cortés</title>
@show
<link href="{{ asset('css/admin.css') }}" rel="stylesheet">
</head>
<body>
<div class="sidebar">
<div class="items">
<div class="head"><span>ADMIN</span></div>
<div class="item"><a href="#">Posts</a></div>
<div class="item"><a href="#">Now</a></div>
<div class="item"><a href="#">Setup</a></div>
<div class="item"><a href="#">Projects</a></div>
<div class="end"><a href="{{ route('index') }}">Volver</a></div>
</div>
</div>
<h1>Admin Panel</h1>
@endsection
<div class="container">
</div>
@section('content')
<script src="js/app.js"></script>
</body>
</html>
@endsection

View File

@@ -0,0 +1,21 @@
@extends('admin.base')
@section('title')
<h1>Create Post</h1>
@endsection
@section('content')
<form action="{{ route('admin.post.save') }}" method="post">
@csrf
<div>
<label for="title">Titulo</label>
<input type="text" id="title" name="title" required/>
</div>
<div>
<label for="md">Contenido</label>
<textarea id="md" name="md"></textarea>
</div>
<input type="submit" value="Crear"/>
</form>
@endsection

View File

@@ -0,0 +1,33 @@
@extends('admin.base')
@section('title')
<h1>Posts</h1>
@endsection
@section('content')
<table>
<thead>
<tr>
<th>Id</th>
<th>Titulo</th>
<th>Fecha</th>
<th class="controls"><a href="{{ route('admin.post.create') }}">create</a></th>
</tr>
</thead>
<tbody>
@foreach($posts as $post)
<tr>
<td>{{$post->id}}</td>
<td>{{$post->title}}</td>
<td>{{$post->created_at->format('Y-m-d')}}</td>
<td class="controls">
<a href="#">edit</a>
<a href="#">delete</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection

View File

@@ -2,11 +2,10 @@
@section('content')
<h1>Archivo</h1>
<ul>
@foreach($posts as $post)
<li>
<a href="{{ route('blog.show', $post->id) }}">{{$post->title}}</a> <span>({{$post->created_at->format('Y-m-d')}})</span>
<a href="{{ route('blog.show', ['post' => $post->id]) }}">{{$post->title}}</a> <span>({{$post->created_at->format('Y-m-d')}})</span>
</li>
@endforeach
</ul>

View File

@@ -5,13 +5,27 @@ Route::post('/login', 'LoginController@login');
Route::get('/now', 'NowController@index')->name('now.index');
Route::get('/blog', 'BlogController@index')->name('blog.index');
Route::get('blog/archive', 'BlogController@archive')->name('blog.archive');
Route::get('/blog/{post}', 'BlogController@show')->name('blog.show');
Route::prefix('blog')->group(function() {
Route::get('/', 'BlogController@index')->name('blog.index');
Route::get('archive', 'BlogController@archive')->name('blog.archive');
Route::get('{post}', 'BlogController@show')->name('blog.show');
});
Route::middleware('auth')->group(function() {
Route::get('/logout', 'LoginController@logout')->name('logout');
Route::get('/admin', 'AdminController@index')->name('admin');
Route::get('logout', 'LoginController@logout')->name('logout');
Route::prefix('admin')->group(function() {
Route::get('/', 'AdminController@index')->name('admin');
Route::prefix('posts')->group(function() {
Route::get('/', 'AdminController@posts')->name('admin.post.index');
Route::get('create', 'PostController@create')->name('admin.post.create');
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::get('/', function () {