Skip to content

Commit

Permalink
Merge pull request #38 from bedus-creation/laravel-10x
Browse files Browse the repository at this point in the history
feat: wip
  • Loading branch information
bedus-creation committed Apr 30, 2023
2 parents 68adaca + 0481c73 commit f6f615e
Show file tree
Hide file tree
Showing 98 changed files with 2,464 additions and 3,433 deletions.
41 changes: 41 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
APP_NAME=Laravel
APP_ENV=testing
APP_KEY=base64:ueq4bQLOOic/K3aQ9sBmu6Dit1dCc6896ew8bzjrc2M=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=sqlite

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
40 changes: 29 additions & 11 deletions app/Application/Admin/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace App\Application\Admin\Controllers;

use Aammui\LaravelTaggable\Models\Category;
use Aammui\LaravelTaggable\Models\Tag;
use App\Application\Admin\Requests\ArticleStoreRequest;
use App\Domain\CMS\Models\Article;
use Illuminate\Http\Request;
use Aammui\LaravelTaggable\Models\Tag;
use App\Http\Controllers\Controller;
use App\Domain\CMS\Models\Post;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class ArticleController extends Controller
{
Expand All @@ -25,14 +28,18 @@ public function index()
return view('admin.articles.index', compact('articles'));
}

public function create(Request $request)
public function create(Request $request): Response
{
$categories = Category::all();
$tags = Tag::all();
return view('admin.articles.create', compact('categories', 'tags'));
$tags = Tag::all();

return Inertia::render('Admin/Articles/Create', [
'categories' => $categories,
'tags' => $tags
]);
}

public function store(ArticleStoreRequest $articleStoreRequest)
public function store(ArticleStoreRequest $articleStoreRequest): RedirectResponse
{
$article = $this->repository->create($articleStoreRequest->all());
$article->addCategory($articleStoreRequest->categories);
Expand All @@ -44,17 +51,28 @@ public function store(ArticleStoreRequest $articleStoreRequest)
}
return redirect()->back()->with('success', 'Article has been created.');
}

public function show(Article $article)
{
return view('admin.articles.show', compact('article'));
}

public function edit(Request $request, $id)
/**
* @param Request $request
* @param $id
* @return Response
*/
public function edit(Request $request, $id): Response
{
$categories = Category::all();
$tags = Tag::all();
$data = $this->repository->with(['media', 'tag', 'category'])->findOrFail($id);
return view('admin.articles.edit', compact('data', 'categories', 'tags'));
$tags = Tag::all();
$article = $this->repository->with(['media', 'tag', 'category'])->findOrFail($id);

return Inertia::render('Admin/Articles/Edit', [
'categories' => $categories,
'tags' => $tags,
'article' => $article
]);
}

public function update(Request $request, $id)
Expand Down
4 changes: 0 additions & 4 deletions app/Application/Admin/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
namespace App\Application\Admin\Controllers;

use Aammui\LaravelMedia\Facades\Media;
use Aammui\LaravelMedia\Traits\HasMedia;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class MediaController extends Controller
{
use HasMedia;

public function __invoke(Request $request)
{
$media = Media::addMedia(request()->image);
return response()->json([
'status' => 'success',
'link' => $media->link()
Expand Down
2 changes: 1 addition & 1 deletion app/Application/Admin/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function store(UserStoreRequest $userStoreRequest)
{
$userStoreRequest->merge(['password' => bcrypt($userStoreRequest->password)]);
$user = $this->repository->create($userStoreRequest->all());
$user->addRole(Role::ADMIN);
$user->addRole(Role::ADMIN->value);
if ($userStoreRequest->image) {
$user->toCollection('cover')
->toDisk('public')
Expand Down
5 changes: 3 additions & 2 deletions app/Application/Admin/Requests/ArticleStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function prepareForValidation()
{
$this->merge([
'user_id' => auth()->id(),
'slug' => Str::slug($this->title),
'slug' => Str::slug($this->title),
]);
}

Expand All @@ -33,7 +33,8 @@ public function authorize()
public function rules()
{
return [
'title' => 'required|min:3'
'title' => 'required|min:3',
'body' => 'required|string'
];
}
}
16 changes: 10 additions & 6 deletions app/Application/Front/Controllers/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@

namespace App\Application\Front\Controllers;

use App\Domain\CMS\Models\Article;
use Illuminate\Http\Request;
use App\Domain\CMS\Models\Post;
use App\Http\Controllers\Controller;

class SitemapController extends Controller
{
public function index()
{
$article = Article::latest()->first();
$article = Post::query()
->latest()
->first();

$content = view('front.sitemap.index', compact('article'));
$content = view('front.sitemap.index', compact('article'));

return response($content, 200)
->header('content-Type', 'text/xml');
}

public function article()
{
$articles = Article::where('status', 'Published')->get();
$articles = Post::query()
->where('status', 'Published')
->get();

$content = view('front.sitemap.article', compact('articles'));

$content = view('front.sitemap.article', compact('articles'));
return response($content, 200)
->header('content-Type', 'text/xml');
}
Expand Down
27 changes: 0 additions & 27 deletions app/Domain/CMS/Models/Article.php

This file was deleted.

27 changes: 22 additions & 5 deletions app/Domain/CMS/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,41 @@

namespace App\Domain\CMS\Models;

use Aammui\LaravelTaggable\Traits\HasTag;
use Aammui\LaravelTaggable\Traits\HasCategory;
use Aammui\LaravelMedia\Traits\HasMedia;
use Aammui\LaravelTaggable\Traits\HasCategory;
use Aammui\LaravelTaggable\Traits\HasTag;
use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;

class Post extends Model
{
use HasCategory, HasTag, HasMedia;

protected $fillable = ['title', 'slug', 'body', 'user_id'];
protected $table = 'posts';

protected $fillable = [
'title',
'slug',
'body',
'type',
'user_id'
];

public function frontUrl()
public function link(): string
{
return url('posts/' . $this->id . '/' . str_slug($this->title));
return url('posts/' . $this->id . '/' . Str::slug($this->title));
}

public function getCoverAttribute()
{
return optional(optional($this->fromCollection('cover')->getMedia())->first())->link()
?? "/assets/img/logo.png";
}

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
6 changes: 3 additions & 3 deletions app/Domain/User/Enums/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Domain\User\Enums;

class Role
enum Role: string
{
const SYSTEM_ADMIN = "system_admin";
const ADMIN = 'admin';
case SYSTEM_ADMIN = "system_admin";
case ADMIN = 'admin';
}
41 changes: 8 additions & 33 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,23 @@
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
* The list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
* Register the exception handling callbacks for the application.
*/
public function render($request, Throwable $exception)
public function register(): void
{
return parent::render($request, $exception);
$this->reportable(function (Throwable $e) {
//
});
}
}
Loading

0 comments on commit f6f615e

Please sign in to comment.