Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.

Commit 87fcb2e

Browse files
committed
Add packages frontend fonctionnalities
1 parent 9bf9de2 commit 87fcb2e

File tree

9 files changed

+241
-98
lines changed

9 files changed

+241
-98
lines changed

app/Http/Controllers/PackageController.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,73 @@
22

33
namespace App\Http\Controllers;
44

5-
use Illuminate\Http\Request;
5+
use App\Repositories\CategoryRepository;
6+
use App\Repositories\PackageRepository;
67

78
class PackageController extends Controller
89
{
9-
public function __construct()
10+
/**
11+
* @var PackageRepository
12+
*/
13+
private $repository;
14+
15+
/**
16+
* @var CategoryRepository
17+
*/
18+
private $categoryRepository;
19+
20+
/**
21+
* PackageController constructor.
22+
* @param PackageRepository $repository
23+
* @param CategoryRepository $categoryRepository
24+
*/
25+
public function __construct(PackageRepository $repository, CategoryRepository $categoryRepository)
1026
{
27+
$this->repository = $repository;
28+
$this->categoryRepository = $categoryRepository;
1129
}
1230

1331
/**
14-
* Display List tutorials
32+
* Display List Packages
1533
*
1634
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
1735
*/
1836
public function index()
1937
{
20-
$packages = [];
38+
$packages = $this->repository->paginate();
39+
$total = $this->repository->online()->count();
40+
$categories = $this->categoryRepository->categoryType('PACKAGE');
41+
$category = null;
2142

22-
return view('frontend.packages.index', compact('packages'));
43+
return view('frontend.packages.index', compact('packages', 'categories', 'total', 'category'));
2344
}
2445

2546
/**
26-
* Display tutorial single Category
47+
* Display Package single Category
2748
*
28-
* @param string $category
49+
* @param string $slug
50+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
2951
*/
30-
public function category(string $category)
52+
public function category(string $slug)
3153
{
54+
$total = $this->repository->online()->count();
55+
$categories = $this->categoryRepository->categoryType('PACKAGE');
56+
$category = $this->categoryRepository->findBySlug($slug);
57+
$packages = $category->packages()->where('is_approved', true)->paginate(6);
3258

59+
return view('frontend.packages.index', compact('packages', 'categories', 'total', 'category'));
3360
}
3461

3562
/**
36-
* Display tutorial show
63+
* Display single package view
3764
*
3865
* @param string $slug
3966
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
4067
*/
4168
public function post(string $slug)
4269
{
43-
return view('frontend.packages.post');
70+
$package = $this->repository->findBySlug($slug);
71+
72+
return view('frontend.packages.post', compact('package'));
4473
}
4574
}

app/Models/Category.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@ class Category extends \TCG\Voyager\Models\Category
66
{
77
protected $fillable = ['slug', 'name', 'type'];
88

9+
/**
10+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
11+
*/
912
public function tutorials()
1013
{
1114
return $this->hasMany(Tutorial::class);
1215
}
16+
17+
/**
18+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
19+
*/
20+
public function packages()
21+
{
22+
return $this->hasMany(Package::class);
23+
}
1324
}

app/Models/Package.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use App\User;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Package extends Model
9+
{
10+
/**
11+
* The attributes that are mass assignable.
12+
*
13+
* @var array
14+
*/
15+
protected $fillable = [
16+
'title', 'slug', 'content', 'resume', 'is_approved', 'image', 'user_id', 'category_id'
17+
];
18+
19+
/**
20+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
21+
*/
22+
public function category()
23+
{
24+
return $this->belongsTo(Category::class);
25+
}
26+
27+
/**
28+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
29+
*/
30+
public function user()
31+
{
32+
return $this->belongsTo(User::class);
33+
}
34+
}

app/Models/Tutorial.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use App\User;
66
use Illuminate\Database\Eloquent\Model;
7-
use TCG\Voyager\Facades\Voyager;
87

98
class Tutorial extends Model
109
{
@@ -14,15 +13,15 @@ class Tutorial extends Model
1413
* @var array
1514
*/
1615
protected $fillable = [
17-
'title', 'slug', 'content', 'is_published', 'image', 'user_id', 'category_id'
16+
'title', 'slug', 'content', 'resume', 'is_published', 'image', 'user_id', 'category_id'
1817
];
1918

2019
/**
2120
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
2221
*/
2322
public function category()
2423
{
25-
return $this->belongsTo(Voyager::modelClass('Category'));
24+
return $this->belongsTo(Category::class);
2625
}
2726

2827
/**
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2018. MckenzieArts
4+
* @author Mckenziearts <[email protected]>
5+
* @link https://github.com/Mckenziearts/laravel-command
6+
*/
7+
8+
namespace App\Repositories;
9+
10+
use App\Models\Package;
11+
12+
class PackageRepository
13+
{
14+
/**
15+
* @var Package
16+
*/
17+
private $model;
18+
19+
/**
20+
* PackageRepository constructor.
21+
* @param Package $model
22+
*/
23+
public function __construct(Package $model)
24+
{
25+
$this->model = $model;
26+
}
27+
28+
/**
29+
* Return a new instance of Package Model
30+
*
31+
* @return Package
32+
*/
33+
public function newInstance()
34+
{
35+
return $this->model->newInstance();
36+
}
37+
38+
/**
39+
* Get all book categories from the database
40+
*
41+
* @return \Illuminate\Database\Eloquent\Collection|static[]
42+
*/
43+
public function online()
44+
{
45+
return $this->model
46+
->newQuery()
47+
->where('is_approved', true)
48+
->get();
49+
}
50+
51+
/**
52+
* Get last post from the database
53+
*
54+
* @param int $limit
55+
* @return \Illuminate\Database\Eloquent\Collection|static[]
56+
*/
57+
public function popular(int $limit = 2)
58+
{
59+
return $this->model->newQuery()
60+
->with('user')
61+
->where('is_approved', true)
62+
->orderBy('created_at', 'DESC')
63+
->limit($limit)
64+
->get();
65+
}
66+
67+
/**
68+
* Get all books categories by count pagination
69+
*
70+
* @param int $results
71+
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
72+
*/
73+
public function paginate(int $results = 6)
74+
{
75+
return $this->model->newQuery()
76+
->with('user')
77+
->where('is_approved', true)
78+
->orderBy('created_at', 'DESC')
79+
->paginate($results);
80+
}
81+
82+
/**
83+
* Return a model with the id set in parameter
84+
*
85+
* @param int $id
86+
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
87+
*/
88+
public function find(int $id)
89+
{
90+
return $this->model->newQuery()
91+
->findOrFail($id);
92+
}
93+
94+
/**
95+
* Return a model with the slug set in parameter
96+
*
97+
* @param string $slug
98+
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
99+
*/
100+
public function findBySlug(string $slug)
101+
{
102+
return $this->model->newQuery()
103+
->with('category')
104+
->where('slug', $slug)
105+
->firstOrFail();
106+
}
107+
}

resources/views/frontend/packages/category.blade.php

Whitespace-only changes.

resources/views/frontend/packages/index.blade.php

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
@extends('layouts.app')
2-
@section('title', __('Packages'))
2+
@if(is_null($category))@section('title', __('Packages'))@else @section('title', __('Packages') . ' | ' . $category->name) @endif
33

44
@section('content')
55

6-
<header class="page-header big_header">
6+
<header class="page-header {{ (is_null($category)) ? 'big_header' : ''}}">
77
<div class="container">
88
<div class="header__text">
9-
<h1 class="page__title">{{ __('Packages') }}</h1>
10-
<p>
11-
{{ __('Do you want to code a module without going from zero? This section offers packages made for Laravel framework') }}
12-
</p>
9+
@if(is_null($category))
10+
<h1 class="page__title">{{ __('Packages') }}</h1>
11+
<p>
12+
{{ __('Do you want to code a module without going from zero? This section offers packages made for Laravel framework') }}
13+
</p>
14+
@else
15+
<h1 class="page__title">{{ $category->name }}</h1>
16+
@endif
1317
</div>
1418
<div class="header__link">
1519
<div class="dropdown">
1620
<button class="btn btn-white dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
1721
{{ __('Categories') }}
1822
</button>
1923
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
20-
<a class="dropdown-item" href="#">Action</a>
21-
<a class="dropdown-item" href="#">Another action</a>
22-
<a class="dropdown-item" href="#">Something else here</a>
24+
<a class="dropdown-item" href="{{ route('packages') }}">{{ __('All') }}</a>
25+
@foreach($categories as $c)
26+
<a class="dropdown-item" href="{{ route('packages.category', ['slug' => $c->slug]) }}">{{ $c->name }}</a>
27+
@endforeach
2328
</div>
2429
</div>
2530
</div>
@@ -31,66 +36,44 @@
3136
<div class="row">
3237
<div class="col-sm-12 col-md-8">
3338
<div class="grid-1">
34-
<article class="card">
35-
<div class="card__thumb">
36-
<img src="{{ asset('img/post-2.png') }}" alt="Tutorial thumb">
37-
</div>
38-
<div class="card__content">
39-
<span class="card__content--date">12 June, 2018</span>
40-
<h4 class="card__content--title">
41-
<a href="javascript:;">Laravel Tenancy – Multi-Tenant Package for Laravel 5.6 and Laravel Lumen</a>
42-
</h4>
43-
<p class="card__content--summary">
44-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias,
45-
animi architecto asperiores deleniti dolor eius error
46-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias,
47-
animi architecto asperiores deleniti dolor eius error et...
48-
</p>
49-
<ul class="card__links">
50-
<li class="author_link">
51-
{{ __('by') }} <a href="javascript:;">Fabrice Yopa</a>
52-
</li>
53-
<li class="read_link">
54-
<a href="javascript:;">{{ __('Read More') }}</a>
55-
</li>
56-
</ul>
57-
</div>
58-
</article>
59-
@for($i = 1; $i <= 4; $i++)
39+
@foreach($packages as $package)
6040
<article class="card">
6141
<div class="card__thumb">
62-
<img src="{{ asset('img/post-2.png') }}" alt="Tutorial thumb">
42+
<img src="{{ asset("storage/$package->image") }}" alt="Package thumb">
6343
</div>
6444
<div class="card__content">
65-
<span class="card__content--date">12 June, 2018</span>
45+
<span class="card__content--date">{{ $package->created_at->format('M d, Y') }}</span>
6646
<h4 class="card__content--title">
67-
<a href="javascript:;">Laravel Tenancy – Multi-Tenant Package for Laravel</a>
47+
<a href="{{ route('packages.post', ['slug' => $package->slug]) }}">{{ $package->title }}</a>
6848
</h4>
6949
<p class="card__content--summary">
70-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias,
71-
animi architecto asperiores deleniti dolor eius error
72-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias,
73-
animi architecto asperiores deleniti dolor eius error et...
50+
{{ str_limit($package->resume, 130) }}
7451
</p>
7552
<ul class="card__links">
7653
<li class="author_link">
77-
{{ __('by') }} <a href="javascript:;">Fabrice Yopa</a>
54+
{{ __('by') }} <a href="javascript:;">{{ $package->user->name }}</a>
7855
</li>
7956
<li class="read_link">
80-
<a href="javascript:;">{{ __('Read More') }}</a>
57+
<a href="{{ route('packages.post', ['slug' => $package->slug]) }}">{{ __('Read More') }}</a>
8158
</li>
8259
</ul>
8360
</div>
8461
</article>
85-
@endfor
62+
@endforeach
8663
</div>
8764
<div class="paginations">
88-
<a href="javascript:;" class="btn btn-primary disabled pagination__left"><i class="icon ion-ios-arrow-back"></i> {{ __('Newer Posts') }}</a>
89-
<a href="javascript:;" class="btn btn-primary pagination__right">{{ __('Older Posts') }} <i class="icon ion-ios-arrow-forward"></i></a>
65+
<?php $pagination = $packages->toArray(); ?>
66+
@if(!is_null($pagination['prev_page_url']))
67+
<a href="{{ $pagination['prev_page_url'] }}" class="btn btn-primary pagination__left"><i class="icon ion-ios-arrow-back"></i> {{ __('Newer Posts') }}</a>
68+
@endif
69+
70+
@if(!is_null($pagination['next_page_url']))
71+
<a href="{{ $pagination['next_page_url'] }}" class="btn btn-primary pagination__right">{{ __('Older Posts') }} <i class="icon ion-ios-arrow-forward"></i></a>
72+
@endif
9073
</div>
9174
</div>
9275
<div class="col-sm-12 col-md-4">
93-
@include('frontend.partials.sidebar', ['name' => __('Total Packages'), 'value' => 150])
76+
@include('frontend.partials.sidebar', ['name' => __('Total Packages'), 'value' => $total])
9477
</div>
9578
</div>
9679
<div class="adwords lcm-2"></div>

0 commit comments

Comments
 (0)