Skip to content

Commit

Permalink
Profil utilizatorul cu postari, terminat
Browse files Browse the repository at this point in the history
  • Loading branch information
brobert04 committed Jan 12, 2023
1 parent cf4a1ba commit e59156c
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 3 deletions.
8 changes: 8 additions & 0 deletions app/Http/Controllers/Admin/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@

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

class PostsController extends Controller
{
public function index(){

if (request('autor')){
$user = User::find(request('autor'));
$posts = Posts::where('user_id', request('autor'))->orderByDesc('created_at')->paginate();
return view('admin.posts.author-page')->with(['user' => $user, 'posts' => $posts]);
// return $user;
}
$posts = Posts::orderByDesc('created_at')->paginate();
return view('admin.posts.posts', compact('posts'));
}
Expand Down
10 changes: 10 additions & 0 deletions app/Models/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@
class Posts extends Model
{
use HasFactory;

/**
* Get the user that owns the Posts
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
}
10 changes: 10 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ class User extends Authenticatable implements MustVerifyEmail
protected $casts = [
'email_verified_at' => 'datetime',
];

/**
* Get all of the comments for the User
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function posts()
{
return $this->hasMany(Posts::class, 'user_id');
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link href="{{asset('../admin/css/adminlte.css')}}" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/adminlte.min.css">
<link href="summernote-bs5.css" rel="stylesheet">
<script src="https://use.fontawesome.com/releases/v6.1.0/js/all.js" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/releases/v6.1.0/js/all.js" crossorigin="anonymous"></script>

@yield('custom-css')
<style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class="fas fa-bars"></i></button>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="{{route('home')}}">Acasă</a></li>
<li><a class="dropdown-item" href="{{route('user.profile')}}">Profil</a></li>
@if(auth()->user()->role == 'autor')
<li><a class="dropdown-item" href="{{ route('admin.posts', ['autor'=> auth()->id]) }}">Postări</a></li>
@endif
<li>
<hr class="dropdown-divider"/>
</li>
Expand Down
84 changes: 84 additions & 0 deletions resources/views/admin/posts/author-page.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
@extends('frontend_views.template')
@section('content')
<div class="row mt-5">
<div class="col-lg-4 mb-5 mb-sm-2">
<div class="author-box border p-5">
<div class="text-center">
<img src="{{ asset('../images/users/' . $user->profile_picture) }}" alt="news" class="img-lg img-fluid img-rounded mb-3">
<p class="fs-12 m-0">Of the Author</p>
<h5 class="mb-2 font-weight-medium">{{ $user->name }}</h5>
<a href="{{ route('user.profile') }}">
@if($user->id == auth()->user()->id)
<i class="fa-solid fa-pen"></i>
@endif
</a>
<p class="text-muted text-center" style="text-transform: capitalize">{{$user->role}}</p>
{{-- <ul class="social-media justify-content-center p-0 mt-3 mb-4">
<li>
<a href="#">
<i class="mdi mdi-instagram"></i>
</a>
</li>
<li>
<a href="#">
<i class="mdi mdi-facebook"></i>
</a>
</li>
<li>
<a href="#">
<i class="mdi mdi-youtube"></i>
</a>
</li>
<li>
<a href="#">
<i class="mdi mdi-linkedin"></i>
</a>
</li>
<li>
<a href="#">
<i class="mdi mdi-twitter"></i>
</a>
</li>
</ul> --}}
</div>
<p>
Odit ut quidem impedit sequi autem ut. Consequatur vel nesciunt
ut perspiciatis omnis praesentium eos.
</p>
<p>
Consequatur maiores laboriosam consequatur ea minus corrupti
perspiciatis illum. Molestiae perspiciatis ea iste eaque ea
sunt. Quae et maiores veritatis cumque facere dolores.
</p>
</div>
</div>
<div class="col-lg-8 mb-5 mb-sm-2">
<div class="row" style="justify-content: center">
@if($posts->count()>0)
@foreach ( $posts as $post )
<div class="col-sm-6 mt-3 mb-5 mb-sm-2">
<div class="position-relative image-hover">
<img src="{{ asset('../images/posts/'.$post->photo) }}" class="img-fluid" alt="world-news">
<span class="thumb-title">{{ $post->user_id }}</span>
</div>
<h5 class="font-weight-600 mt-2">
{{ $post->title }}
</h5>
<p class="fs-15 font-weight-normal">
{{ $post->subtitle }}
</p>
<a href="#" class="font-weight-bold text-dark pt-2">Read Article</a>
</div>
@endforeach
@else
<div class="bg-light border-radius-6 px-4 py-3 mt-4" style="text-align:center;">
<i style="color:black; font-weight: bold; font-size: 35px;"class="fa-solid fa-exclamation"></i>
<p class="text-dark font-weight-bold">
Utilizatorul {{ $user->name }} nu a postat nimic momentan.
</p>
</div>
@endif
</div>
</div>
</div>
@endsection
5 changes: 4 additions & 1 deletion resources/views/admin/posts/posts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
@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><a href="{{ route('admin.posts', ['autor'=> $post->user->id]) }}">{{ $post->user->name }}</a>
<br>
<span class="under-info">{{ $post->user->posts->count() }} postări</span>
</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>
Expand Down
8 changes: 7 additions & 1 deletion resources/views/admin/users.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@
<td class="text-center">
<img class="user-avatar" src="../images/users/{{$user->profile_picture}}">
</td>
<td style="text-transform: capitalize">{{$user->role}}</td>
<td style="text-transform: capitalize">
@if($user->role == 'autor')
<a href="{{ route('admin.posts', ['autor'=> $user->id]) }}">{{$user->role}}</a>
@else
{{ $user->role }}
@endif
</td>
<td class="text-center">
<a href="{{route('users.edit-form', $user->id)}}" class="butoane text-success" title="Editează utilizator"><i class="fa-solid fa-xl fa-pen-to-square"></i></a>
&nbsp;
Expand Down
1 change: 1 addition & 0 deletions resources/views/frontend_views/partials/head.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<link rel="shortcut icon" href="{{asset('../frontend/assets/images/favicon.png')}}" />
<!-- inject:css -->
<link rel="stylesheet" href="{{asset('../frontend/assets/css/style.css')}}">
<script src="https://use.fontawesome.com/releases/v6.1.0/js/all.js" crossorigin="anonymous"></script>
<!-- endinject -->
@yield('custom-css')
</head>

0 comments on commit e59156c

Please sign in to comment.