firstcommit

This commit is contained in:
2025-08-17 16:23:14 +05:45
commit 76bf4c0a18
2648 changed files with 362795 additions and 0 deletions

View File

@@ -0,0 +1,142 @@
<?php
namespace Modules\Blog\app\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\Jobs\SendNewBlogNotification;
use Illuminate\Http\RedirectResponse;
use Modules\Blog\app\Repositories\BlogRepository;
use Modules\Blog\app\Http\Requests\CreateBlogRequest;
class BlogController extends Controller
{
protected $blogRepository;
public function __construct()
{
$this->blogRepository = new BlogRepository;
}
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$perPage = $request->has('per-page') ? $request->input('per-page') : null;
$filter = $request->has('filter') ? $request->input('filter') : [];
$blogs = $this->blogRepository->allBlogs($perPage, $filter);
return view('blog::index', compact('blogs'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('blog::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(CreateBlogRequest $request)
{
try {
$validated = $request->validated();
$blog = $this->blogRepository->storeBlog($validated);
dispatch(new SendNewBlogNotification($blog));
toastr()->success('Blog created successfully.');
return redirect()->route('cms.blogs.index');
} catch (\Throwable $th) {
report($th);
toastr()->error('Something went wrong.');
return back();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('blog::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($uuid)
{
$blog = $this->blogRepository->findBlogByUuid($uuid);
if (!$blog) {
toastr()->error('Blog not found.');
return back();
}
return view('blog::edit', compact('blog'));
}
/**
* Update the specified resource in storage.
*/
public function update(CreateBlogRequest $request, $uuid): RedirectResponse
{
try {
$validated = $request->validated();
$blog = $this->blogRepository->updateBlog($validated, $uuid);
if (!$blog) {
toastr()->error('Blog not found !');
return back();
}
toastr()->success('Blog updated successfully.');
return redirect()->route('cms.blogs.index');
} catch (\Throwable $th) {
report($th);
toastr()->error('Something went wrong.');
return back();
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($uuid)
{
try {
$blog = $this->blogRepository->deleteBlog($uuid);
if (!$blog) {
toastr()->error('Blog not found.');
return back();
}
DB::commit();
toastr()->success('Blog deleted successfully.');
return redirect()->route('cms.blogs.index');
} catch (\Throwable $th) {
DB::rollback();
report($th);
toastr()->error('Something went wrong.');
return back();
}
}
}

View File

View File

@@ -0,0 +1,76 @@
<?php
namespace Modules\Blog\app\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CreateBlogRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'title' => 'required|string|max:255',
'content' => 'required|string',
'author' => 'required|string|max:255',
'summary' => 'required|string',
'published_date' => 'required|date',
'status' => 'required|in:active,inactive',
'meta_title' => 'sometimes|nullable|string|max:255',
'meta_description' => 'sometimes|nullable|string',
'meta_keywords' => 'sometimes|nullable|string|max:255',
'image' => 'sometimes|nullable|mimes:png,jpg,jpeg',
'slug' => 'required',
];
}
public function messages()
{
return [
'title.required' => 'The title field is required.',
'title.string' => 'The title field must be a string.',
'title.max' => 'The title may not be greater than 255 characters.',
'content.required' => 'The content field is required.',
'content.string' => 'The content field must be a string.',
'author.required' => 'The author field is required.',
'author.string' => 'The author field must be a string.',
'author.max' => 'The author may not be greater than 255 characters.',
'summary.required' => 'The summary field is required.',
'summary.string' => 'The summary field must be a string.',
'published_date.required' => 'The published date field is required.',
'published_date.date' => 'The published date field must be a valid date.',
'status.required' => 'The status field is required.',
'status.in' => 'The status field must be either "active" or "inactive".',
'meta_title.string' => 'The meta title field must be a string.',
'meta_title.max' => 'The meta title may not be greater than 255 characters.',
'meta_description.string' => 'The meta description field must be a string.',
'meta_keywords.string' => 'The meta keywords field must be a string.',
'meta_keywords.max' => 'The meta keywords may not be greater than 255 characters.',
'image.mimes' => 'The image must be a file of type: png, jpg, jpeg.',
'slug.required' => 'The slug field is required.',
];
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
// return auth()->user()->can('users.create');
}
}