diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 0bb028a..94bdad3 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -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()]); + } } diff --git a/app/Http/Controllers/NowController.php b/app/Http/Controllers/NowController.php index 774fe95..7e94f59 100644 --- a/app/Http/Controllers/NowController.php +++ b/app/Http/Controllers/NowController.php @@ -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'); + } } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php new file mode 100644 index 0000000..f30d84f --- /dev/null +++ b/app/Http/Controllers/ProjectController.php @@ -0,0 +1,83 @@ +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'); + } +} diff --git a/app/Project.php b/app/Project.php new file mode 100644 index 0000000..e2fff17 --- /dev/null +++ b/app/Project.php @@ -0,0 +1,15 @@ +hasMany('App\ProjectPhoto'); + } +} diff --git a/app/ProjectPhoto.php b/app/ProjectPhoto.php new file mode 100644 index 0000000..3d8cbbe --- /dev/null +++ b/app/ProjectPhoto.php @@ -0,0 +1,14 @@ +belongsTo('App\Project'); + } +} diff --git a/database/migrations/2019_06_22_034600_create_base_db.php b/database/migrations/2019_06_22_034600_create_base_db.php index fdd8f82..dcb1ec2 100644 --- a/database/migrations/2019_06_22_034600_create_base_db.php +++ b/database/migrations/2019_06_22_034600_create_base_db.php @@ -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'); } diff --git a/public/css/admin.css b/public/css/admin.css index 35a2bdb..a070457 100644 --- a/public/css/admin.css +++ b/public/css/admin.css @@ -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; diff --git a/public/css/app.css b/public/css/app.css index 9808a75..2540587 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -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); + } +} + diff --git a/resources/sass/admin.scss b/resources/sass/admin.scss index 3559b68..c72aaa6 100644 --- a/resources/sass/admin.scss +++ b/resources/sass/admin.scss @@ -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; diff --git a/resources/sass/app.scss b/resources/sass/app.scss index bf16349..8618d21 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -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); + } + } +} + diff --git a/resources/views/admin/base.blade.php b/resources/views/admin/base.blade.php index b287e1c..582b7ba 100644 --- a/resources/views/admin/base.blade.php +++ b/resources/views/admin/base.blade.php @@ -11,9 +11,9 @@ diff --git a/resources/views/admin/now/create.blade.php b/resources/views/admin/now/create.blade.php new file mode 100644 index 0000000..3634646 --- /dev/null +++ b/resources/views/admin/now/create.blade.php @@ -0,0 +1,17 @@ +@extends('admin.base') + +@section('title') +

Create Now

+@endsection + +@section('content') +
+ @csrf +
+ + +
+ +
+ +@endsection diff --git a/resources/views/admin/now/edit.blade.php b/resources/views/admin/now/edit.blade.php new file mode 100644 index 0000000..41db73e --- /dev/null +++ b/resources/views/admin/now/edit.blade.php @@ -0,0 +1,16 @@ +@extends('admin.base') + +@section('title') +

Edit Now

+@endsection + +@section('content') +
+ @csrf +
+ + +
+ +
+@endsection diff --git a/resources/views/admin/now/index.blade.php b/resources/views/admin/now/index.blade.php new file mode 100644 index 0000000..30a0d92 --- /dev/null +++ b/resources/views/admin/now/index.blade.php @@ -0,0 +1,34 @@ +@extends('admin.base') + +@section('title') +

Now

+@endsection + +@section('content') + + + + + + + + + + @foreach($nows as $now) + + + + + + @endforeach + +
IdFechacreate
{{$now->id}}{{$now->created_at->format('Y-m-d')}} + edit +
$now->id]) }} method="post"> + @csrf + +
+
+ + +@endsection diff --git a/resources/views/admin/projects/create.blade.php b/resources/views/admin/projects/create.blade.php new file mode 100644 index 0000000..08b7e79 --- /dev/null +++ b/resources/views/admin/projects/create.blade.php @@ -0,0 +1,26 @@ +@extends('admin.base') + +@section('title') +

Create Project

+@endsection + +@section('content') +
+ @csrf +
+ + +
+
+ + +
+
+ + +
+ + +
+ +@endsection diff --git a/resources/views/admin/projects/edit.blade.php b/resources/views/admin/projects/edit.blade.php new file mode 100644 index 0000000..c3f460a --- /dev/null +++ b/resources/views/admin/projects/edit.blade.php @@ -0,0 +1,24 @@ +@extends('admin.base') + +@section('title') +

Edit Post

+@endsection + +@section('content') +
+ @csrf +
+ + +
+
+ + +
+
+ + +
+ +
+@endsection diff --git a/resources/views/admin/projects/index.blade.php b/resources/views/admin/projects/index.blade.php new file mode 100644 index 0000000..874165e --- /dev/null +++ b/resources/views/admin/projects/index.blade.php @@ -0,0 +1,32 @@ +@extends('admin.base') + +@section('title') +

Projects

+@endsection + +@section('content') + + + + + + + + + @foreach($projects as $project) + + + + + @endforeach + +
Titulocreate
{{$project->title}} + edit +
$project->id]) }} method="post"> + @csrf + +
+
+ + +@endsection diff --git a/resources/views/base.blade.php b/resources/views/base.blade.php index cf7ea2b..acf97f9 100644 --- a/resources/views/base.blade.php +++ b/resources/views/base.blade.php @@ -21,7 +21,7 @@ Now