Cree las rutas para la creacion de projectos

This commit is contained in:
Daniel Cortés
2019-07-03 01:28:51 -04:00
parent b15c2dc658
commit 53b709c175
22 changed files with 491 additions and 17 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Http\Controllers;
use App\Post;
use App\Now;
use App\Project;
use Illuminate\Http\Request;
class AdminController extends Controller
@@ -16,4 +18,14 @@ class AdminController extends Controller
{
return view('admin.posts.index', ['posts' => Post::orderBy('created_at', 'desc')->get()]);
}
public function now()
{
return view('admin.now.index', ['nows' => Now::orderBy('created_at', 'desc')->get()]);
}
public function projects()
{
return view('admin.projects.index', ['projects' => Project::orderBy('created_at', 'desc')->get()]);
}
}

View File

@@ -12,4 +12,40 @@ class NowController extends Controller
$now = Now::orderBy('created_at', 'desc')->first();
return view('now.index', ['now' => $now] );
}
public function create()
{
return view('admin.now.create');
}
public function save(Request $request)
{
$now = new Now();
$now->md = $request->md;
$now->save();
return redirect()->route('admin.now.index');
}
public function edit($id)
{
return view('admin.now.edit', ['now' => Now::find($id)]);
}
public function update(Request $request, $id)
{
$now = Now::find($id);
$now->md = $request->md;
$now->update();
return redirect()->route('admin.now.index');
}
public function delete($id)
{
$now= Now::find($id);
$now->delete();
return redirect()->route('admin.now.index');
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace App\Http\Controllers;
use App\Project;
use App\ProjectPhoto;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class ProjectController extends Controller
{
public function index()
{
$projects = Project::orderBy('created_at', 'desc')->get();
return view('projects.index', ['projects' => $projects] );
}
public function create()
{
return view('admin.projects.create');
}
public function save(Request $request)
{
$project = new Project();
$project->title = $request->title;
$project->md = $request->md;
$project->save();
foreach($request->photos as $photo){
$filename = $photo->store('photos');
$projectPhoto = new ProjectPhoto();
$projectPhoto->project_id = $project->id;
$projectPhoto->filename = $filename;
$projectPhoto->save();
}
return redirect()->route('admin.project.index');
}
public function edit($id)
{
return view('admin.projects.edit', ['project' => Project::find($id)]);
}
public function update(Request $request, $id)
{
$project = Project::find($id);
$project->title = $request->title;
$project->md = $request->md;
$project->save();
foreach($project->photos as $photo) {
Storage::delete($photo->filename);
$photo->delete();
}
foreach($request->photos as $photo){
$filename = $photo->store('photos');
$projectPhoto = new ProjectPhoto();
$projectPhoto->project_id = $project->id;
$projectPhoto->filename = $filename;
$projectPhoto->save();
}
return redirect()->route('admin.project.index');
}
public function delete($id)
{
$project = Project::find($id);
foreach($project->photos as $photo) {
Storage::delete($photo->filename);
$photo->delete();
}
$project->delete();
return redirect()->route('admin.project.index');
}
}

15
app/Project.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $table = 'projects';
public function photos()
{
return $this->hasMany('App\ProjectPhoto');
}
}

14
app/ProjectPhoto.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class ProjectPhoto extends Model
{
protected $table = 'projects_photos';
public function project() {
return $this->belongsTo('App\Project');
}
}

View File

@@ -20,10 +20,27 @@ class CreateBaseDb extends Migration
$table->longText('md');
$table->timestamps();
});
Schema::create('projects', function(Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->longText('md');
$table->timestamps();
});
Schema::create('projects_photos', function(Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('project_id')->unsigned();
$table->foreign('project_id')->references('id')->on('projects');
$table->string('filename');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('projects_photos');
Schema::dropIfExists('projects');
Schema::dropIfExists('now');
Schema::dropIfExists('posts');
}

44
public/css/admin.css vendored
View File

@@ -504,6 +504,44 @@ textarea.form-input {
text-transform: uppercase;
}
/* Images
-------------------------------------*/
.image-container {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
.image-container img {
display: block;
margin: 0.5rem;
max-width: calc(100% - 1rem);
}
@media screen and (min-width: 600px) {
.image-container {
-webkit-flex-direction: row;
flex-direction: row;
}
.image-container img {
max-width: calc((100% / 2) - 1rem);
}
}
@media screen and (min-width: 768px) {
.image-container {
-webkit-flex-direction: row;
flex-direction: row;
}
.image-container img {
max-width: calc((100% / 3) - 1rem);
}
}
/* Base
-------------------------------------*/
@@ -604,6 +642,12 @@ textarea.form-input {
text-align: left;
}
.table td.controls,
.table th.controls {
margin-left: 0;
margin-right: auto;
}
.table td.controls a,
.table td.controls input[type=submit] {
display: block;

38
public/css/app.css vendored
View File

@@ -504,3 +504,41 @@ textarea.form-input {
text-transform: uppercase;
}
/* Images
-------------------------------------*/
.image-container {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
.image-container img {
display: block;
margin: 0.5rem;
max-width: calc(100% - 1rem);
}
@media screen and (min-width: 600px) {
.image-container {
-webkit-flex-direction: row;
flex-direction: row;
}
.image-container img {
max-width: calc((100% / 2) - 1rem);
}
}
@media screen and (min-width: 768px) {
.image-container {
-webkit-flex-direction: row;
flex-direction: row;
}
.image-container img {
max-width: calc((100% / 3) - 1rem);
}
}

View File

@@ -99,6 +99,11 @@ $sidebar-width: 13rem;
text-align: left;
}
td.controls, th.controls {
margin-left: 0;
margin-right: auto;
}
td.controls {
a, input[type=submit]{
display: block;

View File

@@ -3,11 +3,12 @@
@import "variables.scss";
/* Base
-------------------------------------*/
-------------------------------------*/
html {
overflow-y: scroll;
background-color: white;
}
body {
font-size: 15px;
line-height: 1.6rem;
@@ -124,3 +125,34 @@ textarea.form-input {
text-transform: uppercase;
}
/* Images
-------------------------------------*/
.image-container {
display: flex;
flex-wrap: wrap;
img {
display: block;
margin: .5rem;
max-width: calc(100% - 1rem);
}
}
@media screen and (min-width: 600px) {
.image-container {
flex-direction: row;
img {
max-width: calc((100% / 2) - 1rem);
}
}
}
@media screen and (min-width: 768px) {
.image-container {
flex-direction: row;
img {
max-width: calc((100% / 3) - 1rem);
}
}
}

View File

@@ -11,9 +11,9 @@
<div class="sidebar-items">
<div class="sidebar-head"><span>Admin</span></div>
<div class="sidebar-item"><a href="{{ route('admin.post.index') }}" class="sidebar-link">Posts</a></div>
<div class="sidebar-item"><a href="#" class="sidebar-link">Now</a></div>
<div class="sidebar-item"><a href="{{ route('admin.now.index') }}" class="sidebar-link">Now</a></div>
<div class="sidebar-item"><a href="#" class="sidebar-link">Setup</a></div>
<div class="sidebar-item"><a href="#" class="sidebar-link">Projects</a></div>
<div class="sidebar-item"><a href="{{ route('admin.project.index') }}" class="sidebar-link">Projects</a></div>
<div class="sidebar-end"><a href="{{ route('index') }}" class="sidebar-link">Volver</a></div>
</div>
</div>

View File

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

View File

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

View File

@@ -0,0 +1,34 @@
@extends('admin.base')
@section('title')
<h1>Now</h1>
@endsection
@section('content')
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Fecha</th>
<th class="controls"><a href="{{ route('admin.now.create') }}">create</a></th>
</tr>
</thead>
<tbody>
@foreach($nows as $now)
<tr>
<td>{{$now->id}}</td>
<td>{{$now->created_at->format('Y-m-d')}}</td>
<td class="controls">
<a href="{{ route('admin.now.edit', ['now' => $now->id]) }}">edit</a>
<form action={{ route('admin.now.delete', ['now' => $now->id]) }} method="post">
@csrf
<input type="submit" value="delete"/>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection

View File

@@ -0,0 +1,26 @@
@extends('admin.base')
@section('title')
<h1>Create Project</h1>
@endsection
@section('content')
<form action="{{ route('admin.project.save') }}" enctype="multipart/form-data" method="post">
@csrf
<div>
<label for="title">Titulo</label>
<input type="text" class="form-input" id="title" name="title" required/>
</div>
<div>
<label for="md">Descripcion</label>
<textarea id="md" class="form-input" name="md"></textarea>
</div>
<div>
<label for="photos">Fotos</label>
<input multiple="multiple" id="photos" class="form-input" name="photos[]" type="file">
</div>
<input type="submit" class="form-submit" value="Crear"/>
</form>
@endsection

View File

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

View File

@@ -0,0 +1,32 @@
@extends('admin.base')
@section('title')
<h1>Projects</h1>
@endsection
@section('content')
<table class="table">
<thead>
<tr>
<th>Titulo</th>
<th class="controls"><a href="{{ route('admin.project.create') }}">create</a></th>
</tr>
</thead>
<tbody>
@foreach($projects as $project)
<tr>
<td>{{$project->title}}</td>
<td class="controls">
<a href="{{ route('admin.project.edit', ['project' => $project->id]) }}">edit</a>
<form action={{ route('admin.project.delete', ['project' => $project->id]) }} method="post">
@csrf
<input type="submit" value="delete"/>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection

View File

@@ -21,7 +21,7 @@
<a class="navbar-item-link" href="{{route('now.index')}}">Now</a>
</li>
<li class="navbar-item">
<a class="navbar-item-link" href="{{route('projects')}}">Proyectos</a>
<a class="navbar-item-link" href="{{route('project.index')}}">Proyectos</a>
</li>
<li class="navbar-item">
<a class="navbar-item-link" href="{{route('setup')}}">Setup</a>

View File

@@ -1,5 +0,0 @@
@extends('base')
@section('content')
<h1>Now</h1>
@endsection

View File

@@ -1,5 +0,0 @@
@extends('base')
@section('content')
<h1>Projects</h1>
@endsection

View File

@@ -0,0 +1,22 @@
@extends('base')
@php
$parse = new Parsedown();
@endphp
@section('content')
@foreach($projects as $project)
<section>
<h1>{{ $project->title }}</h1>
{!! $parse->text($project->md) !!}
<div class="image-container">
@foreach($project->photos as $photo)
<img src="{{ Storage::url($photo->filename) }}"/>
@endforeach
</div>
</section>
@endforeach
<hr/>
@endsection

View File

@@ -5,6 +5,8 @@ Route::post('/login', 'LoginController@login');
Route::get('/now', 'NowController@index')->name('now.index');
Route::get('/projects', 'ProjectController@index')->name('project.index');
Route::prefix('blog')->group(function() {
Route::get('/', 'BlogController@index')->name('blog.index');
Route::get('archive', 'BlogController@archive')->name('blog.archive');
@@ -25,6 +27,24 @@ Route::middleware('auth')->group(function() {
Route::post('{post}/edit', 'PostController@update')->name('admin.post.update');
Route::post('{post}/delete', 'PostController@delete')->name('admin.post.delete');
});
Route::prefix('now')->group(function() {
Route::get('/', 'AdminController@now')->name('admin.now.index');
Route::get('create', 'NowController@create')->name('admin.now.create');
Route::post('create', 'NowController@save')->name('admin.now.save');
Route::get('{post}/edit', 'NowController@edit')->name('admin.now.edit');
Route::post('{post}/edit', 'NowController@update')->name('admin.now.update');
Route::post('{post}/delete', 'NowController@delete')->name('admin.now.delete');
});
Route::prefix('projects')->group(function() {
Route::get('/', 'AdminController@projects')->name('admin.project.index');
Route::get('create', 'ProjectController@create')->name('admin.project.create');
Route::post('create', 'ProjectController@save')->name('admin.project.save');
Route::get('{post}/edit', 'ProjectController@edit')->name('admin.project.edit');
Route::post('{post}/edit', 'ProjectController@update')->name('admin.project.update');
Route::post('{post}/delete', 'ProjectController@delete')->name('admin.project.delete');
});
});
});
@@ -32,9 +52,6 @@ Route::get('/', function () {
return view('index');
})->name('index');
Route::get('/projects', function () {
return view('projects');
})->name('projects');
Route::get('/setup', function () {
return view('setup');