Skip to content

Commit

Permalink
Table + model + seeder + factory postari terminat ++ table & paginare…
Browse files Browse the repository at this point in the history
… backend pentru pagina de postari termiant
  • Loading branch information
brobert04 committed Jan 10, 2023
1 parent 1b65173 commit cf4a1ba
Show file tree
Hide file tree
Showing 23 changed files with 136 additions and 59 deletions.
15 changes: 15 additions & 0 deletions app/Http/Controllers/Admin/PostsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Posts;
use Illuminate\Http\Request;

class PostsController extends Controller
{
public function index(){
$posts = Posts::orderByDesc('created_at')->paginate();
return view('admin.posts.posts', compact('posts'));
}
}
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\ServiceProvider;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Lang;

class AppServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -39,5 +40,6 @@ public function boot()
});

View::composer('frontend_views.*', NavbarComposer::class);
Paginator::useBootstrap();
}
}
4 changes: 3 additions & 1 deletion database/factories/CategoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ class CategoryFactory extends Factory
*/
public function definition()
{
$title = $this->faker->sentence(3, $asText=true);
$title = $this->faker->sentence(1, $asText=true);
$slug = Str::slug($title, '-');

return [
'title'=>$title,
'slug'=>$slug,
'subtitle'=>$this->faker->sentence(3, true),
'excerpt' => $this->faker->paragraph(rand(1,3), true),
'views' => rand(0, 2000),
'photo'=> 'category.jpg',
'meta_title' => $this->faker->words(rand(1,5), true),
'meta_description' => $this->faker->sentence(3, true),
'meta_keywords' => $this->faker->words(rand(1,8), true),
Expand Down
5 changes: 4 additions & 1 deletion database/factories/PostsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ public function definition()
{
$title = $this->faker->sentence(3, $asText=true);
$slug = Str::slug($title, '-');
$created_at = $this->faker->dateTimeBetween('-2 year', 'now');
return [
'title'=>$title,
'slug'=>$slug,
'subtitle'=>$this->faker->sentence(3, true),
'content' => $this->faker->paragraph(rand(6,15), true),
'views' => rand(0, 10000),
'published_at' => $this->faker->randomElement(array(null, $this->faker->dateTimeBetween('-2 year', 'now'))),
'published_at' => $this->faker->randomElement(array(null, $created_at)),
'created_at' => $created_at,
'photo' => 'post.jpg',
'user_id' => User::all()->where('role','autor')->random(),
'meta_title' => $this->faker->words(rand(1,5), true),
'meta_description' => $this->faker->sentence(3, true),
Expand Down
1 change: 1 addition & 0 deletions database/seeders/CategorySeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class CategorySeeder extends Seeder
*/
public function run()
{
Category::truncate();
Category::factory(6)->create();
}
}
2 changes: 1 addition & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function run()
$this->call([
CategorySeeder::class,
UserSeeder::class,
PostsSeeder::class,
// PostsSeeder::class,
]);
}
}
1 change: 1 addition & 0 deletions database/seeders/PostsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PostsSeeder extends Seeder
*/
public function run()
{
Posts::truncate();
Posts::factory(70)->create();
}
}
File renamed without changes
Binary file removed public/images/users/AnnFox_1671478974.jpeg
Binary file not shown.
Binary file removed public/images/users/BrennaAtkinson_1671955906.jpeg
Binary file not shown.
Binary file removed public/images/users/CarlyQuinn_1671906948.png
Binary file not shown.
Binary file removed public/images/users/GabrielCarter_1671882367.jpeg
Binary file not shown.
Binary file removed public/images/users/GriffithVargas_1671389232.jpeg
Binary file not shown.
Binary file removed public/images/users/KarynStewart_1671389880.jpeg
Binary file not shown.
Binary file removed public/images/users/Olivia-Campbell_1671301394.jpeg
Binary file not shown.
Binary file removed public/images/users/RobertGabriel_1671960702.png
Binary file not shown.
Binary file removed public/images/users/Rose Mccarty_1671301143.jpeg
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,26 @@
Utilizatori
</a>
@endif
<div class="sb-sidenav-menu-heading">Content</div>
<div class="sb-sidenav-menu-heading">Conținut</div>
@can('author-rights')
<a class="nav-link" href="{{route('categories')}}">
<div class="sb-nav-link-icon"><i class="fa-solid fa-list"></i></div>
Categorii
</a>
@endcan
<a class="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#collapseLayouts"
aria-expanded="false" aria-controls="collapseLayouts">
<div class="sb-nav-link-icon"><i class="fas fa-columns"></i></div>
Layouts
<div class="sb-nav-link-icon"><i class="fa-solid fa-file"></i></div>
Postări
<div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
</a>
<div class="collapse" id="collapseLayouts" aria-labelledby="headingOne"
data-bs-parent="#sidenavAccordion">
<nav class="sb-sidenav-menu-nested nav">
<a class="nav-link" href="layout-static.html">Static Navigation</a>
<a class="nav-link" href="layout-sidenav-light.html">Light Sidenav</a>
<a class="nav-link" href="{{ route('admin.posts') }}">Toate Postările</a>
<a class="nav-link" href="layout-sidenav-light.html">Postări Publicate</a>
</nav>
</div>
<a class="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#collapsePages"
aria-expanded="false" aria-controls="collapsePages">
<div class="sb-nav-link-icon"><i class="fas fa-book-open"></i></div>
Pages
<div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
</a>
<div class="collapse" id="collapsePages" aria-labelledby="headingTwo"
data-bs-parent="#sidenavAccordion">
<nav class="sb-sidenav-menu-nested nav accordion" id="sidenavAccordionPages">
<a class="nav-link collapsed" href="#" data-bs-toggle="collapse"
data-bs-target="#pagesCollapseAuth" aria-expanded="false"
aria-controls="pagesCollapseAuth">
Authentication
<div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
</a>
<div class="collapse" id="pagesCollapseAuth" aria-labelledby="headingOne"
data-bs-parent="#sidenavAccordionPages">
<nav class="sb-sidenav-menu-nested nav">
<a class="nav-link" href="login.html">Login</a>
<a class="nav-link" href="register.html">Register</a>
<a class="nav-link" href="password.html">Forgot Password</a>
</nav>
</div>
<a class="nav-link collapsed" href="#" data-bs-toggle="collapse"
data-bs-target="#pagesCollapseError" aria-expanded="false"
aria-controls="pagesCollapseError">
Error
<div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
</a>
<div class="collapse" id="pagesCollapseError" aria-labelledby="headingOne"
data-bs-parent="#sidenavAccordionPages">
<nav class="sb-sidenav-menu-nested nav">
<a class="nav-link" href="401.html">401 Page</a>
<a class="nav-link" href="404.html">404 Page</a>
<a class="nav-link" href="500.html">500 Page</a>
</nav>
</div>
</nav>
</div>
<div class="sb-sidenav-menu-heading">Addons</div>
<a class="nav-link" href="charts.html">
<div class="sb-nav-link-icon"><i class="fas fa-chart-area"></i></div>
Charts
</a>
<a class="nav-link" href="tables.html">
<div class="sb-nav-link-icon"><i class="fas fa-table"></i></div>
Tables
</a>
</div>
</div>
</nav>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<nav class="sb-topnav navbar navbar-expand navbar-dark bg-dark">
<!-- Navbar Brand-->
<a class="navbar-brand ps-3" href="{{route('dashboard')}}">Panou de Control</a>
<a class="navbar-brand ps-3" href="{{route('dashboard')}}">World News</a>
<!-- Sidebar Toggle-->
<button class="btn btn-link btn-sm order-1 order-lg-0 me-4 me-lg-0" id="sidebarToggle" href="#!"><i
class="fas fa-bars"></i></button>
Expand Down
92 changes: 92 additions & 0 deletions resources/views/admin/posts/posts.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
@extends('admin.layouts.layout-dashboard')
@section('title', 'Gestionare Postări')
@section('content')
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="{{route('dashboard')}}">Panou Control</a></li>
<li class="breadcrumb-item active">Postări</li>
</ol>
@if(session()->has('success'))
<div class="alert alert-success" id="alert">
{{ session()->get('success') }}
</div>
@endif
@if(session()->has('error'))
<div class="alert alert-danger" id="alert">
{{ session()->get('error') }}
</div>
@endif
<div class="card mb-4">
<div class="card-header">
Postări - {{$posts->count() }}
@can('author-rights')<a href="" class=" float-end ">Adaugă Postare</a>@endcan
</div>
<div class="card-body">
<table class="table table-bordered">
<thead>
<tr>
<th>Titlu</th>
<th>Autor</th>
<th>Thumbnail</th>
<th>Vizualizări</th>
<th>Meta Description & Meta Keywords</th>
<th>Acțiuni</th>
</tr>
</thead>
<tbody>
@foreach ($posts as $post )
<tr>
<td>{{ $post->title }} <br> <span class="under-info">{{ $post->created_at->format('F j, Y') }}</span></td>
<td>{{ $post->user_id }}</td>
<td><img style="max-width: 100px; max-height: 100px"class="img-thumbnail" src="{{ asset('../images/posts/' .$post->photo) }}"></td>
<td>{{ $post->views }}</td>
<td>
{{$post->meta_description}}
<br>
<span id="keywords" class="badge bg-primary">{{$post->meta_keywords}}</span>
</td>
<td class="text-center">
<a href="{{route('users.edit-form', $post->id)}}" class="butoane text-success" title="Editează utilizator"><i class="fa-solid fa-xl fa-pen-to-square"></i></a>
&nbsp;
<form id="delete-form-{{$post->id}}" action="{{route('users.delete', $post->id)}}" method="post" style="display:inline-block;">
@csrf
@method('DELETE')
</form>
<button class="butoane text-danger" title="Șterge postare" onclick="if(confirm('Confirmați ștergerea postării {{$post->title}}?')){
event.preventDefault();
document.getElementById('delete-form-'+{{$post->id}}).submit();}
"><i class="fa-sharp fa-xl fa-solid fa-trash"></i></button>
</td>
</tr>
@endforeach
</tbody>
<tfoot>
{{ $posts->links() }}
</tfoot>
</table>
</div>
</div>
@endsection
@section('custom-css')
<style>
.butoane{
text-decoration: none !important;
background:none !important;
border:none !important;
}
.user-avatar{
max-height: 50px;
max-width: 50px;
}
.under-info{
color: gray;
font-size: 12px;
}
</style>
@endsection
@section('custom-js')
<script>
setTimeout(()=>{
document.getElementById('alert').style.display = 'none';
}, 3000);
</script>
@endsection
1 change: 0 additions & 1 deletion resources/views/frontend_views/partials/head.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<link rel="shortcut icon" href="{{asset('../frontend/assets/images/favicon.png')}}" />
<!-- inject:css -->
<link rel="stylesheet" href="{{asset('../frontend/assets/css/style.css')}}">

<!-- endinject -->
@yield('custom-css')
</head>
2 changes: 1 addition & 1 deletion resources/views/frontend_views/partials/scripts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script src="{{asset('../frontend/assets/vendors/owl.carousel/dist/owl.carousel.min.js')}}"></script>
<!-- End plugin js for this page -->
<!-- Custom js for this page-->
<script src="{{asset('../frontend/assets/js/demo.js')}}"></script>
<script src="{{ asset('../frontend/assets/js/demo.js') }}"></script>
<!-- End custom js for this page-->
<script>
let search = document.querySelector('#search')
Expand Down
8 changes: 8 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Illuminate\Support\Facades\Route;
use \App\Http\Controllers\Admin\UsersController;
use \App\Http\Controllers\Admin\UserProfile;
use App\Http\Controllers\Admin\PostsController;

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -43,6 +44,10 @@
Route::get('categories/edit/{id}', [\App\Http\Controllers\Admin\CategoryController::class,'editCategoryForm'])->name('categories.edit-form');
Route::put('categories/edit/{id}', [\App\Http\Controllers\Admin\CategoryController::class,'editCategory'])->name('categories.edit');
Route::delete('categories/delete/{id}', [\App\Http\Controllers\Admin\CategoryController::class,'deleteCategory'])->name('categories.delete');


// RUTELE PENTRU POSTARI
Route::get('posts', [PostsController::class, 'index'])->name('admin.posts');
});

//======Rutele utilizatorului========
Expand All @@ -54,5 +59,8 @@
});





Route::view('/forgot-password', 'auth.forgot-password')->middleware('guest')->name('password.request');
require __DIR__.'/auth.php';

0 comments on commit cf4a1ba

Please sign in to comment.