Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
59 changes: 59 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

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

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"

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

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto eol=lf

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.env.production
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode
27 changes: 27 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
}

/**
* Register the commands for the application.
*/
protected function commands(): void
{
$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');
}
}
30 changes: 30 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* The list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Register the exception handling callbacks for the application.
*/
public function register(): void
{
$this->reportable(function (Throwable $e) {
//
});
}
}
122 changes: 122 additions & 0 deletions app/Http/Controllers/Admin/ArticleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\ArticleStoreRequest;
use App\Http\Requests\ArticleUpdateRequest;
use App\Models\Article;
use App\Models\Category;
use App\Models\Tag;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Illuminate\View\View;
use Intervention\Image\Facades\Image;

class ArticleController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(): View
{
$getArticleList = Article::orderByDesc('id')->with('category', 'author')->paginate(10);
return view('admin.article.index', compact('getArticleList'));
}

/**
* Show the form for creating a new resource.
*/
public function create(): View
{
$categories = Category::pluck('name', 'id');
$tags = Tag::pluck('name', 'id');
return view('admin.article.create', compact(['categories', 'tags']));
}

/**
* Store a newly created resource in storage.
*/
public function store(ArticleStoreRequest $request): RedirectResponse
{
$filename = uniqid() . '.' . $request->file('image')->extension();

$article = new Article();
$article->title = $request->input('title');
$article->content = $request->input('content');
$article->slug = Str::slug($request->input('slug'));
$article->image = $filename;
$article->category_id = $request->input('category');
$article->user_id = auth()->id();
$article->save();
if (!empty($request->input('tag'))) {
$article->tags()->attach($request->input('tag'));
}
$uploadedImg = $request->file('image')->storeAs('article/images', $filename, 'public');
Image::make(storage_path('app/public/' . $uploadedImg))->resize(550, 300)->save();


return redirect()->route('admin.article.index')->with('success_message', 'Article has been created successfully!');
}

/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
$article = Article::with(['category', 'tags'])->findOrFail($id);
$categories = Category::pluck('name', 'id');
$tags = Tag::pluck('name', 'id');
return view('admin.article.edit', compact('article', 'categories', 'tags'));
}

/**
* Update the specified resource in storage.
*/
public function update(ArticleUpdateRequest $request, string $id)
{

$article = Article::findOrFail($id);
$article->title = $request->input('title');
$article->content = $request->input('content');
$article->slug = Str::slug($request->input('slug'));
$article->category_id = $request->input('category');
$article->user_id = auth()->id();
if ($request->hasFile('image')) {
$filename = uniqid() . '.' . $request->file('image')->extension();
Storage::disk('public')->delete('article/images/' . $article->image);
$article->image = $filename;
$uploadedImg = $request->file('image')->storeAs('article/images', $filename, 'public');
Image::make(storage_path('app/public/' . $uploadedImg))->resize(550, 300)->save();
}
$article->save();

if (!empty($request->input('tag'))) {
$article->tags()->sync($request->input('tag'));
}

return redirect()->route('admin.article.index')->with(['success_message' => 'The article was successfully updated.']);
}

/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
$article = Article::find($id);
$article->tags()->detach();
Storage::disk('public')->delete('article/images/' . $article->image);
$article->delete();
return redirect()->route('admin.article.index')->with(['success_message' => 'The category was successfully deleted.']);
}
}
44 changes: 44 additions & 0 deletions app/Http/Controllers/Admin/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\CategoryStoreRequest;
use App\Http\Requests\Admin\CategoryUpdateRequest;
use App\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class CategoryController extends Controller
{
public function index()
{
$getCategoryList = Category::paginate(7);

return view('admin.category.index', compact('getCategoryList'));
}

public function store(CategoryStoreRequest $request)
{
Category::create($request->validated());
return redirect()->route('admin.category.index')->with('success_message', 'Category has been created successfully!');
}

public function update(CategoryUpdateRequest $request, string $id)
{
$updateCategory = Category::findOrFail($id);
$updateCategory->update($request->validated());
if(!$updateCategory->wasChanged()) {
$message = ['info_message' => 'You have not change anything. Nothing to update!'];
} else {
$message = ['success_message' => 'The category was successfully updated.'];
}
return redirect()->route('admin.category.index')->with($message);
}

public function destroy(string $id)
{
$category = Category::destroy($id);
return redirect()->route('admin.category.index')->with(['success_message' => 'The category was successfully deleted.']);
}
}
42 changes: 42 additions & 0 deletions app/Http/Controllers/Admin/TagController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\TagStoreRequest;
use App\Http\Requests\Admin\TagUpdateRequest;
use App\Models\Tag;
use Illuminate\Http\Request;

class TagController extends Controller
{
public function index()
{
$getTagList = Tag::paginate(5);
return view('admin.tag.index', compact('getTagList'));
}

public function store(TagStoreRequest $request)
{
Tag::create($request->validated());
return redirect()->route('admin.tag.index')->with('success_message', 'Tag has been created successfully!');
}

public function update(TagUpdateRequest $request, string $id)
{
$updateTag = Tag::findOrFail($id);
$updateTag->update($request->validated());
if(!$updateTag->wasChanged()) {
$message = ['info_message' => 'You have not change anything. Nothing to update!'];
} else {
$message = ['success_message' => 'The tag was successfully updated.'];
}
return redirect()->route('admin.tag.index')->with($message);
}

public function destroy(string $id)
{
$category = Tag::destroy($id);
return redirect()->route('admin.tag.index')->with(['success_message' => 'The category was successfully deleted.']);
}
}
Loading