Skip to content

Commit

Permalink
Merge branch '174-upgrade-to-Laravel-11'
Browse files Browse the repository at this point in the history
  • Loading branch information
alimranahmed committed Jun 22, 2024
2 parents 53c49f8 + d10587c commit c1031f4
Show file tree
Hide file tree
Showing 53 changed files with 3,521 additions and 3,489 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.3'
extensions: pcov
ini-values: |
pcov.enabled=1
coverage: pcov

- name: Cache dependencies
uses: actions/cache@v1
Expand Down Expand Up @@ -72,5 +76,12 @@ jobs:
DB_USERNAME: root
DB_PASSWORD: password
run: |
vendor/bin/phpunit
vendor/bin/phpunit --coverage-clover clover.xml
vendor/bin/pint
- name: Generate test coverage badge
uses: timkrase/phpunit-coverage-badge@v1.2.0
with:
coverage_badge_path: 'badge-coverage.svg'
push_badge: true
repo_token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ _ide_helper.php
*.swp
*.swo
.phpunit.result.cache
/tests/coverage
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[![Test Coverage](https://raw.githubusercontent.com/alimranahmed/LaraBlog/main/badge-coverage.svg)](https://packagist.org/packages/alimranahmed/LaraBlog)
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)


# Blog Using Laravel 10
# Blog Using Laravel 11
### Let's keep it as simple as possible. Configure anything you want
A full-featured blogging system for personal use. No frontend theme and anything heavy or unnecessary library used.

### Technologies used
1. [TailwindCSS](https://tailwindcss.com/)
2. [Alpine.js](https://alpinejs.dev/)
3. [Laravel](https://laravel.com/)
4. [Livewire](https://laravel-livewire.com/)
1. [TailwindCSS](https://tailwindcss.com)
2. [Alpine.js](https://alpinejs.dev)
3. [Laravel](https://laravel.com)
4. [Livewire](https://livewire.laravel.com)

### There are four several types of users with several permissions
1. Admin/Owner
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class Kernel extends HttpKernel
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
//vendor added
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
];

/**
Expand Down
36 changes: 0 additions & 36 deletions app/Http/Livewire/Backend/Config/Index.php

This file was deleted.

54 changes: 0 additions & 54 deletions app/Http/Livewire/Backend/User/Form.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Livewire\Backend\Article;
namespace App\Livewire\Backend\Article;

use App\Mail\NotifySubscriberForNewArticle;
use App\Models\Article;
Expand All @@ -18,36 +18,37 @@ class Form extends Component
{
public Article $originalArticle;

public $article;
public array $articleData = [];

public string $method;

public array $rules = [
'article.heading' => 'required',
'article.slug' => 'required',
'article.category_id' => 'required',
'article.content' => 'required',
'article.language' => 'required',
'article.is_comment_enabled' => 'boolean',
'article.meta.description' => 'nullable|string',
'article.meta.image_url' => 'nullable|url',
'articleData.heading' => 'required',
'articleData.slug' => 'required',
'articleData.category_id' => 'required',
'articleData.content' => 'required',
'articleData.language' => 'required',
'articleData.is_comment_enabled' => 'boolean',
'articleData.meta.description' => 'nullable|string',
'articleData.meta.image_url' => 'nullable|url',
];

public function mount(?Article $article = null): void
{
if ($article->id) {
$this->originalArticle = $article;
$this->article = $article->toArray();
$this->article['keywords'] = $this->originalArticle->keywords->pluck('name')->implode(' ');
$this->articleData = $article->toArray();
$this->articleData['keywords'] = $article->keywords->pluck('name')->implode(' ');
$this->articleData['meta'] = $article->meta ?: [];
}

$this->method = $article->id ? 'put' : 'post';
}

public function render(): View
{
if (Arr::get($this->article, 'heading')) {
$this->article['slug'] = Str::slug(Arr::get($this->article, 'heading'), '-', Arr::get($this->article, 'language'));
if (Arr::get($this->articleData, 'heading')) {
$this->articleData['slug'] = Str::slug(Arr::get($this->articleData, 'heading'), '-', Arr::get($this->articleData, 'language'));
}
$categories = Category::query()->active()->get();

Expand All @@ -56,7 +57,7 @@ public function render(): View

public function submit(): void
{
$data = Arr::get($this->validate(), 'article');
$data = Arr::get($this->validate(), 'articleData');

if ($this->method == 'post') {
$this->store($data);
Expand Down Expand Up @@ -100,7 +101,7 @@ protected function update(array $updateData): void

$this->originalArticle->keywords()->detach();

$keywordsToAttach = array_unique(explode(' ', Arr::get($this->article, 'keywords')));
$keywordsToAttach = array_unique(explode(' ', Arr::get($this->articleData, 'keywords')));

foreach ($keywordsToAttach as $keywordToAttach) {
/** @var Keyword $newKeyword */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<?php

namespace App\Http\Livewire\Backend\Article;
namespace App\Livewire\Backend\Article;

use App\Models\Article;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\On;
use Livewire\Attributes\Url;
use Livewire\Component;

class Index extends Component
{
public $category = '';
#[Url]
public string $category = '';

public $query = '';
#[Url]
public string $query = '';

public $keyword = '';

protected $queryString = [
'category' => ['except' => ''],
'keyword' => ['except' => ''],
'query' => ['except' => ''],
];
#[Url]
public string $keyword = '';

protected $listeners = ['articleDeleted' => '$refresh'];

public function render()
public function render(): View
{
$articles = $this->getArticles();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<?php

namespace App\Http\Livewire\Backend\Article;
namespace App\Livewire\Backend\Article;

use App\Models\Article;
use Illuminate\Contracts\View\View;
use Livewire\Component;

class IndexRow extends Component
{
public $article;
public ?Article $article = null;

public function mount(Article $article)
public function mount(Article $article): void
{
$this->article = $article;
}

public function render()
public function render(): View
{
return view('livewire.backend.article.index-row');
}

public function togglePublish()
public function togglePublish(): void
{
$this->article->update([
'is_published' => ! $this->article->is_published,
Expand All @@ -29,10 +30,10 @@ public function togglePublish()
$this->article->refresh();
}

public function destroy()
public function destroy(): void
{
$this->article->update(['is_deleted' => 1]);

$this->emitUp('articleDeleted');
$this->dispatch('articleDeleted')->to(Index::class);
}
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
<?php

namespace App\Http\Livewire\Backend\Category;
namespace App\Livewire\Backend\Category;

use App\Models\Category;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Arr;
use Livewire\Component;

class Index extends Component
{
public $adding = false;
public bool $adding = false;

public $category;
public array $category = [];

protected $listeners = ['categoryDeleted' => '$refresh'];

public function render()
public function render(): View
{
$categories = $this->getCategories();

return view('livewire.backend.category.index', compact('categories'));
}

public function startAdding()
public function startAdding(): void
{
$this->adding = true;
}

public function store()
public function store(): void
{
$data = $this->validate(['category.name' => 'required', 'category.alias' => 'required']);

Category::create(Arr::get($data, 'category'));
Category::query()->create(Arr::get($data, 'category'));

$this->adding = false;
}

protected function getCategories(): LengthAwarePaginator
{
return Category::with(['articles' => function ($articles) {
return $articles->notDeleted();
}])->orderBy('name')
return Category::query()
->with(['articles' => fn (HasMany $articles) => $articles->notDeleted()])
->orderBy('name')
->paginate();
}
}
Loading

0 comments on commit c1031f4

Please sign in to comment.