Init(Core): Change repo

This commit is contained in:
2026-04-24 15:29:37 +03:30
commit ededb41a3a
1499 changed files with 199187 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Art;
use App\Models\Book;
use App\Models\Branch;
use App\Models\Chapter;
use App\Models\Division;
use App\Models\Gate;
use App\Models\Law;
use App\Models\Part;
use App\Models\Section;
use App\Models\Volum;
use Illuminate\Http\Request;
class ArtController extends Controller
{
public function index(Request $request)
{
$query = Art::query();
if ($request->filled('q')) {
$q = $request->q;
$query->where(function ($qry) use ($q) {
$qry->where('title', 'like', "%{$q}%")->orWhere('text', 'like', "%{$q}%");
});
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$arts = $query->paginate($perPage)->withQueryString();
return view('admin.art.index', compact('arts'));
}
public function create()
{
$chapters = Chapter::all();
$parts = Part::all();
$gates = Gate::all();
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$sections = Section::all();
$divisions = Division::all();
$branches = Branch::all();
return view('admin.art.create', compact('chapters', 'parts', 'gates', 'books', 'volums', 'laws', 'sections','branches','divisions'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required',
'text' => 'required',
'number' => 'required',
'chapter_id' => 'nullable',
'part_id' => 'nullable',
'gate_id' => 'nullable',
'section_id' => 'nullable',
'book_id' => 'nullable',
'volum_id' => 'nullable',
'law_id' => 'required',
'division_id' => 'nullable',
'branch_id' => 'nullable',
'is_free' => 'nullable'
]);
$validated['is_free'] = $request->input('is_free') ? true : false;
art::query()->create($validated);
return redirect(route('art.index'));
}
public function edit(art $art)
{
$chapters = Chapter::all();
$parts = Part::all();
$gates = Gate::all();
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$sections = Section::all();
$divisions = Division::all();
$branches = Branch::all();
return view('admin.art.update', compact('art', 'chapters', 'parts', 'gates', 'books', 'volums', 'laws', 'sections','branches','divisions'));
}
public function update(Request $request, Art $art)
{
$validated = $request->validate([
'title' => 'required',
'text' => 'required',
'number' => 'required',
'chapter_id' => 'nullable',
'part_id' => 'nullable',
'gate_id' => 'nullable',
'section_id' => 'nullable',
'book_id' => 'nullable',
'volum_id' => 'nullable',
'law_id' => 'required',
'division_id' => 'nullable',
'branch_id' => 'nullable',
'is_free' => 'nullable'
]);
$validated['is_free'] = $request->input('is_free') ? true : false;
$art->update($validated);
return redirect(route('art.edit',$art->id));
}
public function destroy(Art $art)
{
$art->delete();
return redirect(route('art.index'));
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Book;
use App\Models\Law;
use App\Models\Volum;
use Illuminate\Http\Request;
class BookController extends Controller
{
public function index(Request $request)
{
$query = Book::query();
if ($request->filled('q')) {
$query->where('title', 'like', '%' . $request->q . '%');
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$books = $query->paginate($perPage)->withQueryString();
return view('admin.book.index', compact('books'));
}
public function create()
{
$volums = Volum::all();
$laws = Law::all();
return view('admin.book.create', compact('volums', 'laws'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'volum_id' => 'required',
'law_id' => 'nullable',
]);
book::query()->create($validated);
return redirect(route('book.index'));
}
public function edit(Book $book)
{
$volums = Volum::all();
$laws = Law::all();
return view('admin.book.update', compact('book', 'volums', 'laws'));
}
public function update(Request $request, Book $book)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'volum_id' => 'required',
'law_id' => 'nullable',
]);
$book->update($validated);
return redirect(route('book.index'));
}
public function destroy(Book $book)
{
$book->delete();
return redirect(route('book.index'));
}
}

View File

@@ -0,0 +1,108 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Book;
use App\Models\Branch;
use App\Models\Chapter;
use App\Models\Division;
use App\Models\Gate;
use App\Models\Law;
use App\Models\Part;
use App\Models\Section;
use App\Models\Volum;
use Illuminate\Http\Request;
class BranchController extends Controller
{
public function index(Request $request)
{
$query = Branch::query();
if ($request->filled('q')) {
$query->where('title', 'like', '%' . $request->q . '%');
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$branchs = $query->paginate($perPage)->withQueryString();
return view('admin.branch.index', compact('branchs'));
}
public function create()
{
$chapters = Chapter::all();
$parts = Part::all();
$gates = Gate::all();
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$sections = Section::all();
$divisions = Division::all();
return view('admin.branch.create', compact('chapters', 'parts', 'gates', 'books', 'volums', 'laws', 'sections','divisions'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'chapter_id' => 'nullable',
'part_id' => 'nullable',
'gate_id' => 'nullable',
'section_id' => 'nullable',
'book_id' => 'nullable',
'volum_id' => 'required',
'law_id' => 'required',
'division' => 'nullable',
]);
branch::query()->create($validated);
return redirect(route('branch.index'));
}
public function edit(branch $branch)
{
$chapters = Chapter::all();
$parts = Part::all();
$gates = Gate::all();
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$sections = Section::all();
$divisions = Division::all();
return view('admin.branch.update', compact('branch', 'chapters', 'parts', 'gates', 'books', 'volums', 'laws', 'sections','divisions'));
}
public function update(Request $request, Branch $branch)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'chapter_id' => 'nullable',
'part_id' => 'nullable',
'gate_id' => 'nullable',
'section_id' => 'nullable',
'book_id' => 'nullable',
'volum_id' => 'required',
'law_id' => 'required',
'division_id' => 'nullable',
]);
$branch->update($validated);
return redirect(route('branch.index'));
}
public function destroy(Branch $branch)
{
$branch->delete();
return redirect(route('branch.index'));
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\category\CreateCategoryRequest;
use App\Http\Requests\admin\category\UpdateCategoryRequest;
use App\Models\Category;
class CategoriesController extends Controller
{
public function index()
{
$categories = Category::query()->select('id', 'name', 'label')->get();
return view('admin.categories.index', compact('categories'));
}
public function create()
{
return view('admin.categories.create');
}
public function store(CreateCategoryRequest $request)
{
Category::query()->create($request->validated());
return redirect(route('categories.index'));
}
public function edit(Category $category)
{
return view('admin.categories.update', compact('category'));
}
public function update(UpdateCategoryRequest $request, Category $category)
{
$category->update($request->validated());
return redirect(route('categories.index'));
}
public function destroy(Category $category)
{
$category->delete();
return back();
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Category;
use Illuminate\Http\Request;
class CategoryController extends Controller
{
public function index(Request $request)
{
$query = Category::query();
if ($request->filled('q')) {
$query->where('name', 'like', '%' . $request->q . '%');
}
if ($request->filled('type')) {
$query->where('type', $request->type);
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$categories = $query->paginate($perPage)->withQueryString();
return view('admin.categories.index', compact('categories'));
}
public function create()
{
return view('admin.categories.create');
}
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required',
'type' => 'required'
]);
Category::create($validated);
return redirect(route('categories.index'));
}
public function edit(Category $category)
{
return view('admin.categories.update',compact('category'));
}
public function update(Request $request, Category $category)
{
$validated = $request->validate([
'name' => 'required',
'type' => 'required'
]);
$category->update($validated);
return redirect(route('categories.index'));
}
public function destroy(Category $category)
{
$category->delete();
return redirect(route('categories.index'));
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Book;
use App\Models\Chapter;
use App\Models\Division;
use App\Models\Law;
use App\Models\Section;
use App\Models\Volum;
use Illuminate\Http\Request;
class ChapterController extends Controller
{
public function index(Request $request)
{
$query = Chapter::query();
if ($request->filled('q')) {
$query->where('title', 'like', '%' . $request->q . '%');
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$chapters = $query->paginate($perPage)->withQueryString();
return view('admin.chapter.index', compact('chapters'));
}
public function create()
{
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$sections = Section::all();
$divisions = Division::all();
return view('admin.chapter.create', compact('sections', 'books', 'volums', 'laws','divisions'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'section_id' => 'nullable',
'book_id' => 'nullable',
'volum_id' => 'nullable',
'law_id' => 'nullable',
'division_id' => 'nullable'
]);
Chapter::query()->create($validated);
return redirect(route('chapter.index'));
}
public function edit(Chapter $chapter)
{
$sections = Section::all();
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$divisions = Division::all();
return view('admin.chapter.update', compact('sections', 'chapter', 'books', 'volums', 'laws','divisions'));
}
public function update(Request $request, Chapter $chapter)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'section_id' => 'nullable',
'book_id' => 'nullable',
'volum_id' => 'nullable',
'law_id' => 'nullable',
'division_id' => 'nullable'
]);
$chapter->update($validated);
return redirect(route('chapter.index'));
}
public function destroy(Chapter $chapter)
{
$chapter->delete();
return redirect(route('chapter.index'));
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Book;
use App\Models\Division;
use App\Models\Law;
use App\Models\Volum;
use Illuminate\Http\Request;
class DivisionController extends Controller
{
public function index(Request $request)
{
$query = Division::query();
if ($request->filled('q')) {
$query->where('title', 'like', '%' . $request->q . '%');
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$divisions = $query->paginate($perPage)->withQueryString();
return view('admin.division.index', compact('divisions'));
}
public function create()
{
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
return view('admin.division.create', compact('books', 'volums', 'laws'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'book_id' => 'nullable',
'volum_id' => 'required',
'law_id' => 'required',
]);
division::query()->create($validated);
return redirect(route('division.index'));
}
public function edit(division $division)
{
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
return view('admin.division.update', compact('division','books', 'volums', 'laws'));
}
public function update(Request $request, Division $division)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'book_id' => 'nullable',
'volum_id' => 'required',
'law_id' => 'required',
]);
$division->update($validated);
return redirect(route('division.index'));
}
public function destroy(Division $division)
{
$division->delete();
return redirect(route('division.index'));
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Book;
use App\Models\Chapter;
use App\Models\Division;
use App\Models\Gate;
use App\Models\Law;
use App\Models\Part;
use App\Models\Section;
use App\Models\Volum;
use Illuminate\Http\Request;
class GateController extends Controller
{
public function index(Request $request)
{
$query = Gate::query();
if ($request->filled('q')) {
$query->where('title', 'like', '%' . $request->q . '%');
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$gates = $query->paginate($perPage)->withQueryString();
return view('admin.gate.index', compact('gates'));
}
public function create()
{
$parts = Part::all();
$chapters = Chapter::all();
$sections = Section::all();
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$divisions = Division::all();
return view('admin.gate.create', compact('parts', 'chapters', 'sections', 'books', 'volums', 'laws','divisions'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'part_id' => 'nullable',
'division_id' => 'nullable',
]);
Gate::query()->create($validated);
return redirect(route('gate.index'));
}
public function edit(Gate $gate)
{
$parts = Part::all();
$chapters = Chapter::all();
$sections = Section::all();
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$divisions = Division::all();
return view('admin.gate.update', compact('gate', 'parts', 'chapters', 'sections', 'books', 'volums', 'laws','divisions'));
}
public function update(Request $request, Gate $gate)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'part_id' => 'nullable',
'division_id' => 'nullable',
]);
$gate->update($validated);
return redirect(route('gate.index'));
}
public function destroy(Gate $gate)
{
$gate->delete();
return redirect(route('gate.index'));
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
public function index()
{
return view('admin.dashboard');
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Art;
use App\Models\JudicialPrecedent;
use Illuminate\Http\Request;
class JudicialPrecedentController extends Controller
{
public function index(Request $request)
{
$query = JudicialPrecedent::query();
if ($request->filled('q')) {
$q = $request->q;
$query->where(function ($qry) use ($q) {
$qry->where('ruling_number', 'like', "%{$q}%")
->orWhere('subject', 'like', "%{$q}%")
->orWhere('full_text', 'like', "%{$q}%");
});
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$judicialPrecedents = $query->paginate($perPage)->withQueryString();
return view('admin.judicial-precedent.index', compact('judicialPrecedents'));
}
public function create()
{
$arts = Art::all();
return view('admin.judicial-precedent.create', compact('arts'));
}
public function store(Request $request)
{
$validated = $request->validate([
'ruling_number' => 'required|unique:judicial_precedents,ruling_number',
'ruling_date' => 'required|date',
'subject' => 'required|string',
'full_text' => 'required|string',
'issuing_authority' => 'nullable|string',
'art_ids' => 'nullable|array',
'art_ids.*' => 'exists:arts,id'
]);
$judicialPrecedent = JudicialPrecedent::create([
'ruling_number' => $validated['ruling_number'],
'ruling_date' => $validated['ruling_date'],
'subject' => $validated['subject'],
'full_text' => $validated['full_text'],
'issuing_authority' => $validated['issuing_authority'] ?? 'هیأت عمومی دیوان عالی کشور'
]);
if (!empty($validated['art_ids'])) {
$judicialPrecedent->arts()->attach($validated['art_ids']);
}
return redirect(route('judicial-precedent.index'));
}
public function edit(JudicialPrecedent $judicialPrecedent)
{
$arts = Art::all();
$selectedArtIds = $judicialPrecedent->arts->pluck('id')->toArray();
return view('admin.judicial-precedent.update', compact('judicialPrecedent', 'arts', 'selectedArtIds'));
}
public function update(Request $request, JudicialPrecedent $judicialPrecedent)
{
$validated = $request->validate([
'ruling_number' => 'required|unique:judicial_precedents,ruling_number,' . $judicialPrecedent->id,
'ruling_date' => 'required|date',
'subject' => 'required|string',
'full_text' => 'required|string',
'issuing_authority' => 'nullable|string',
'art_ids' => 'nullable|array',
'art_ids.*' => 'exists:arts,id'
]);
$judicialPrecedent->update($validated);
$judicialPrecedent->arts()->sync($validated['art_ids'] ?? []);
return redirect(route('judicial-precedent.edit', $judicialPrecedent->id));
}
public function destroy(JudicialPrecedent $judicialPrecedent)
{
$judicialPrecedent->delete();
return redirect(route('judicial-precedent.index'));
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Models\Law;
use Illuminate\Http\Request;
class LawController extends Controller
{
public function index(Request $request)
{
$query = Law::query();
if ($request->filled('q')) {
$query->where('title', 'like', '%' . $request->q . '%');
}
if ($request->filled('locked')) {
$query->where('is_locked', $request->locked === '1');
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$laws = $query->paginate($perPage)->withQueryString();
return view('admin.law.index', compact('laws'));
}
public function create()
{
$categories = Category::all();
return view('admin.law.create', compact('categories'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'is_locked' => 'nullable',
'category_id' => 'nullable|integer|exists:categories,id',
'price' => 'nullable|numeric',
'image' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$validated['is_locked'] = $request->has('is_locked', false);
if ($request->hasFile('image') && $request->file('image')->isValid()) {
dd($request->has('image'));
$imageName = uniqid('image_', true) . '.' . $request->file('image')->getClientOriginalExtension();
$request->file('image')->move(public_path('images'), $imageName);
$validated['image'] = $imageName;
}
Law::create($validated);
return redirect()->route('law.index')->with('success', 'Law created successfully.');
}
public function edit(Law $law)
{
$categories = Category::all();
return view('admin.law.update', compact('law', 'categories'));
}
public function update(Request $request, Law $law)
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'is_locked' => 'sometimes',
'category_id' => 'nullable|integer',
'price' => 'nullable|numeric',
'image' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$validated['is_locked'] = $request->boolean('is_locked');
if ($request->hasFile('image') && $request->file('image')->isValid()) {
$imageName = uniqid('image_', true) . '.' . $request->file('image')->getClientOriginalExtension();
$request->file('image')->move(public_path('images'), $imageName);
$validated['image'] = $imageName;
}
$law->update($validated);
return redirect()->route('law.index');
}
public function destroy(Law $law)
{
$law->delete();
return redirect(route('law.index'));
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Notification\StoreRequest;
use App\Http\Requests\admin\Notification\UpdateRequest;
use App\Models\Notification;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
public function index(Request $request)
{
$query = Notification::query();
if ($request->filled('q')) {
$q = $request->q;
$query->where(function ($qry) use ($q) {
$qry->where('title', 'like', "%{$q}%")
->orWhere('description', 'like', "%{$q}%");
});
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$notifications = $query->latest()->paginate($perPage)->withQueryString();
return view('admin.notifications.index', compact('notifications'));
}
public function create()
{
return view('admin.notifications.create');
}
public function store(StoreRequest $request)
{
Notification::create($request->validated());
return redirect()->route('notifications.index');
}
public function edit(Notification $notification)
{
return view('admin.notifications.update', compact('notification'));
}
public function update(UpdateRequest $request, Notification $notification)
{
$notification->update($request->validated());
return redirect()->route('notifications.index');
}
public function destroy(Notification $notification)
{
$notification->delete();
return redirect()->route('notifications.index');
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Book;
use App\Models\Chapter;
use App\Models\Division;
use App\Models\Law;
use App\Models\Part;
use App\Models\Section;
use App\Models\Volum;
use Illuminate\Http\Request;
class PartController extends Controller
{
public function index(Request $request)
{
$query = Part::query();
if ($request->filled('q')) {
$query->where('title', 'like', '%' . $request->q . '%');
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$parts = $query->paginate($perPage)->withQueryString();
return view('admin.part.index', compact('parts'));
}
public function create()
{
$chapters = Chapter::all();
$sections = Section::all();
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$divisions = Division::all();
return view('admin.part.create', compact('chapters', 'sections', 'books', 'volums', 'laws','divisions'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'chapter_id' => 'nullable',
'section_id' => 'nullable',
'book_id' => 'nullable',
'volum_id' => 'nullable',
'law_id' => 'nullable',
'division_id' => 'nullable'
]);
Part::query()->create($validated);
return redirect(route('part.index'));
}
public function edit(Part $part)
{
$chapters = Chapter::all();
$sections = Section::all();
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$divisions = Division::all();
return view('admin.part.update', compact('part', 'chapters', 'sections', 'books', 'volums', 'laws','divisions'));
}
public function update(Request $request, Part $part)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'chapter_id' => 'nullable',
'section_id' => 'nullable',
'book_id' => 'nullable',
'volum_id' => 'nullable',
'law_id' => 'nullable',
'division_id' => 'nullable'
]);
$part->update($validated);
return redirect(route('part.index'));
}
public function destroy(Part $part)
{
$part->delete();
return redirect(route('part.index'));
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Book;
use App\Models\Division;
use App\Models\Law;
use App\Models\Section;
use App\Models\Volum;
use Illuminate\Http\Request;
class SectionController extends Controller
{
public function index(Request $request)
{
$query = Section::query();
if ($request->filled('q')) {
$query->where('title', 'like', '%' . $request->q . '%');
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$sections = $query->paginate($perPage)->withQueryString();
return view('admin.section.index', compact('sections'));
}
public function create()
{
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$sections = Section::all();
$divisions = Division::all();
return view('admin.section.create', compact('books', 'volums', 'laws','sections','divisions'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'book_id' => 'nullable',
'volum_id' => 'nullable',
'law_id' => 'nullable',
'division_id' => 'nullable'
]);
section::query()->create($validated);
return redirect(route('section.index'));
}
public function edit(Section $section)
{
$books = Book::all();
$volums = Volum::all();
$laws = Law::all();
$sections = Section::all();
$divisions = Division::all();
return view('admin.section.update', compact('section', 'books', 'volums', 'laws','sections','divisions'));
}
public function update(Request $request, Section $section)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'book_id' => 'nullable',
'volum_id' => 'nullable',
'law_id' => 'nullable',
'division_id' => 'nullable'
]);
$section->update($validated);
return redirect(route('section.index'));
}
public function destroy(Section $section)
{
$section->delete();
return redirect(route('section.index'));
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\SubscribePlan\CreateRequest;
use App\Http\Requests\admin\SubscribePlan\UpdateRequest;
use App\Models\SubscribePlan;
use Illuminate\Http\Request;
class SubscribePlanController extends Controller
{
public function index(Request $request)
{
$query = SubscribePlan::query();
if ($request->filled('q')) {
$q = $request->q;
$query->where('name', 'like', "%{$q}%");
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$subscribePlans = $query->paginate($perPage)->withQueryString();
return view('admin.subscribe-plans.index', compact('subscribePlans'));
}
public function create()
{
return view('admin.subscribe-plans.create');
}
public function store(CreateRequest $request)
{
$validated = $request->validated();
$validated['is_active'] = $request->has('is_active');
$validated['is_free'] = $request->has('is_free');
SubscribePlan::create($validated);
return redirect()->route('subscribe-plans.index');
}
public function edit(SubscribePlan $subscribePlan)
{
return view('admin.subscribe-plans.update', compact('subscribePlan'));
}
public function update(UpdateRequest $request, SubscribePlan $subscribePlan)
{
$validated = $request->validated();
$validated['is_active'] = $request->has('is_active');
$validated['is_free'] = $request->has('is_free');
$subscribePlan->update($validated);
return redirect()->route('subscribe-plans.index');
}
public function destroy(SubscribePlan $subscribePlan)
{
$subscribePlan->delete();
return redirect()->route('subscribe-plans.index');
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Suggestion;
use Illuminate\Http\Request;
class SuggestionController extends Controller
{
public function index(Request $request)
{
$query = Suggestion::query()->with('user');
if ($request->filled('q')) {
$q = $request->q;
$query->where(function ($qry) use ($q) {
$qry->where('text', 'like', "%{$q}%")
->orWhereHas('user', fn ($u) => $u->where('mobile', 'like', "%{$q}%"));
});
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$suggestions = $query->paginate($perPage)->withQueryString();
return view('admin.suggestions.index', compact('suggestions'));
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\user\CreateUserRequest;
use App\Http\Requests\admin\user\UpdateUserRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
class UsersController extends Controller
{
public function index(Request $request)
{
$query = User::select('id', 'name', 'email', 'mobile', 'is_admin')
->with(['userSubscribers' => function ($q) {
$q->where('expired_at', '>=', now());
}]);
if ($request->filled('q')) {
$q = $request->q;
$query->where(function ($qry) use ($q) {
$qry->where('name', 'like', "%{$q}%")
->orWhere('email', 'like', "%{$q}%")
->orWhere('mobile', 'like', "%{$q}%");
});
}
if ($request->filled('type') && in_array($request->type, ['0', '1'])) {
$query->where('is_admin', (bool) $request->type);
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$users = $query->paginate($perPage)->withQueryString();
return view('admin.users.index', compact('users'));
}
public function create()
{
return view('admin.users.create');
}
public function store(CreateUserRequest $request)
{
$validated = $request->validated();
$validated['password'] = Hash::make(fake()->password);
$validated['is_admin'] = $validated['is_admin'] == 'on' ? true : false;
User::query()->create($validated);
return redirect(route('users.index'));
}
public function edit(User $user)
{
return view('admin.users.update', compact('user'));
}
public function update(UpdateUserRequest $request, User $user)
{
$validated = $request->validated();
$validated['is_admin'] = $validated['is_admin'] == 'on' ? true : false;
$user->update($validated);
return redirect(route('users.index'));
}
public function destroy(User $user)
{
$user->delete();
return back();
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\CreateVersionStore;
use App\Http\Requests\admin\UpdateVersionStore;
use App\Models\Version;
use Illuminate\Http\Request;
class VersionController extends Controller
{
public function index(Request $request)
{
$query = Version::query();
if ($request->filled('q')) {
$q = $request->q;
$query->where(function ($qry) use ($q) {
$qry->where('code', 'like', "%{$q}%")
->orWhere('number', 'like', "%{$q}%")
->orWhere('type', 'like', "%{$q}%");
});
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$versions = $query->paginate($perPage)->withQueryString();
return view('admin.versions.index', compact('versions'));
}
public function create()
{
return view('admin.versions.create');
}
public function store(CreateVersionStore $request)
{
$validated = $request->validated();
if (isset($validated['force_update'])) {
$validated['force_update'] = $validated['force_update'] == 'on' ? 1 : 0;
}
Version::create($validated);
return redirect(route('versions.index'));
}
public function edit(Version $version)
{
return view('admin.versions.update', compact('version'));
}
public function update(UpdateVersionStore $request, Version $version)
{
$validated = $request->validated();
if (isset($validated['force_update'])) {
$validated['force_update'] = $validated['force_update'] == 'on' ? 1 : 0;
}
$version->update($validated);
return redirect(route('versions.index'));
}
public function destroy(Version $version)
{
$version->delete();
return redirect(route('versions.index'));
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Law;
use App\Models\Volum;
use Illuminate\Http\Request;
class VolumController extends Controller
{
public function index(Request $request)
{
$query = Volum::query();
if ($request->filled('q')) {
$query->where('title', 'like', '%' . $request->q . '%');
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$volums = $query->paginate($perPage)->withQueryString();
return view('admin.volum.index', compact('volums'));
}
public function create()
{
$laws = Law::all();
return view('admin.volum.create', compact('laws'));
}
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'law_id' => 'required',
]);
volum::query()->create($validated);
return redirect(route('volum.index'));
}
public function edit(Volum $volum)
{
$laws = Law::all();
return view('admin.volum.update', compact('volum', 'laws'));
}
public function update(Request $request, Volum $volum)
{
$validated = $request->validate([
'title' => 'required',
'number' => 'required',
'law_id' => 'required',
]);
$volum->update($validated);
return redirect(route('volum.index'));
}
public function destroy(Volum $volum)
{
$volum->delete();
return redirect(route('volum.index'));
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\SuggestionRequest;
use App\Models\Suggestion;
use App\Traits\BaseApiResponse;
class SuggestionController extends Controller
{
use BaseApiResponse;
public function index(SuggestionRequest $requst)
{
Suggestion::create([
'user_id' => auth()->user()->id,
'text' => $requst->text
]);
return $this->success(null,'موفقیت','پیشنهاد شما با موفقیت برای مدیر ارسال شد');
}
}

View File

@@ -0,0 +1,500 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Requests\GetApiRequest;
use App\Models\Art;
use App\Models\Book;
use App\Models\Branch;
use App\Models\Category;
use App\Models\Chapter;
use App\Models\Division;
use App\Models\Gate;
use App\Models\Law;
use App\Models\LikeArt;
use App\Models\Note;
use App\Models\Part;
use App\Models\Section;
use App\Models\Volum;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
class ArtController extends Controller
{
use BaseApiResponse;
public function index(GetApiRequest $request)
{
$arts = Art::with(['chapter', 'part', 'volum', 'law', 'book', 'section', 'gate'])->where('book_id', $request->book_id)->orderBy('number')->get();
$arts = $arts->map(function ($art) {
return [
'id' => $art->id,
'text' => $art->text,
'number' => $art->number,
'chapter' => $art->chapter != null ? [
'id' => $art->chapter->id,
'title' => $art->chapter->title,
'number' => $art->chapter->number,
] : null,
'part' => $art->part != null ? [
'id' => $art->part->id,
'title' => $art->part->title,
'number' => $art->part->number,
] : null,
'volum' => $art->volum != null ? [
'id' => $art->volum->id,
'title' => $art->volum->title,
'number' => $art->volum->number,
] : null,
'law' => $art->law != null ? [
'id' => $art->law->id,
'title' => $art->law->title,
'number' => $art->law->number,
] : null,
'book' => $art->book != null ? [
'id' => $art->book->id,
'title' => $art->book->title,
'number' => $art->book->number,
] : null,
'section' => $art->section != null ? [
'id' => $art->section->id,
'title' => $art->section->title,
'number' => $art->section->number,
] : null,
'gate' => $art->gate != null ? [
'id' => $art->gate->id,
'title' => $art->gate->title,
'number' => $art->gate->number,
] : null,
];
});
return response()->json(['arts' => $arts]);
}
public function single($id)
{
$art = Art::select('id', 'title', 'number', 'text', 'law_id')->find($id);
if (!$art) {
return $this->failed([], 'Art not found');
}
$law = Law::find($art?->law_id);
$art->is_like = $this->isLiked($art->id);
$art->note = Note::select('id', 'note', 'color_code','created_at')->where('user_id', auth()->user()->id)->where('art_id', $id)->get();
$art->category = $law?->category?->name;
$art->route = array_values($this->route(Art::class, $art));
$previousArt = Art::select('id', 'title', 'number', 'text', 'law_id')
->where('law_id',$art->law_id)
->where('number', '<', $art->number)
->orderBy('number', 'desc')
->first();
if ($previousArt) {
$previousLaw = Law::find($previousArt->law_id);
$previousArt->is_like = $this->isLiked($previousArt->id);
$previousArt->note = Note::select('id', 'note', 'color_code')->where('user_id', auth()->user()->id)->where('art_id', $previousArt->id)->get();
$previousArt->category = $previousLaw?->category?->name;
$previousArt->route = array_values($this->route(Art::class, $previousArt));
}
$nextArt = Art::select('id', 'title', 'number', 'text', 'law_id')
->where('law_id',$art->law_id)
->where('number', '>', $art->number)
->orderBy('number')
->first();
if ($nextArt) {
$nextLaw = Law::find($nextArt->law_id);
$nextArt->is_like = $this->isLiked($nextArt->id);
$nextArt->note = Note::select('id', 'note', 'color_code')->where('user_id', auth()->user()->id)->where('art_id', $nextArt->id)->get();
$nextArt->category = $nextLaw?->category?->name;
$nextArt->route = array_values($this->route(Art::class, $nextArt));
}
$results = array_values(array_filter([$previousArt, $art, $nextArt]));
return $this->success($results);
}
public function like(Art $art)
{
$userId = auth()->id();
$existingLike = LikeArt::query()->where('art_id', $art->id)
->where('user_id', $userId)
->first();
if ($existingLike) {
$existingLike->delete();
return $this->success(null, 'Success', 'Art unliked successfully');
}
LikeArt::create([
'art_id' => $art->id,
'user_id' => $userId,
]);
return $this->success(null, 'Success', 'Art liked successfully');
}
private function isLiked($art_id): bool
{
return LikeArt::query()->where('art_id', $art_id)
->where('user_id', auth()->user()->id)
->exists();
}
public function likes()
{
$likes = LikeArt::query()->where('user_id', auth()->user()->id)
->with('art')
->get()
->map(function ($q) {
return [
'id' => $q->art->id,
'title' => $q->art->title,
'text' => $q->art->text
];
});
return $this->success($likes);
}
public function search(Request $request)
{
$validated = $request->validate([
'book_id' => 'nullable|array',
'volume_id' => 'nullable|array',
'division_id' => 'nullable|array',
'section_id' => 'nullable|array',
'part_id' => 'nullable|array',
'gate_id' => 'nullable|array',
'law_id' => 'nullable|array',
'chapter_id' => 'nullable|array',
'branch_id' => 'nullable|array',
'category_id' => 'nullable|int',
'per_page' => 'nullable|integer',
'search' => 'nullable|string'
]);
$models = [
Law::class,
Volum::class,
Book::class,
Division::class,
Section::class,
Chapter::class,
Part::class,
Gate::class,
Branch::class,
Art::class
];
$results = [];
foreach ($models as $modelClass) {
$results = array_merge($results, $this->searchModel($modelClass, $validated));
}
return $this->success($results);
}
private function searchModel($modelClass, $validated)
{
$query = $modelClass::query();
$filters = [
'law_id',
'volume_id',
'division_id',
'section_id',
'part_id',
'gate_id',
'chapter_id',
'branch_id'
];
$model = new $modelClass;
if ($model->getTable() == 'art') {
$query->where(function ($query) use ($validated, $filters) {
if (!empty($validated['search'])) {
$query->where(function ($q) use ($validated) {
$q->where('title', 'LIKE', "%{$validated['search']}%")
->orWhere('text', 'LIKE', "%{$validated['search']}%");
});
}
foreach ($filters as $filter) {
if (!empty($validated[$filter])) {
$query->whereIn($filter, $validated[$filter]);
}
}
});
if (!empty($validated['category_id'])) {
$query->whereIn('law_id', Category::where('type', $this->convertValueTo($validated['category_id']))->get()->pluck('id'));
}
$items = $query->paginate($validated['per_page'] ?? 10);
return $items->map(function ($item) use ($validated, $modelClass) {
$text = $item->text ?? '';
$search = preg_quote($validated['search'] ?? '', '/');
if (!empty($text) && preg_match('/\b(.{0,50})\b(' . $search . ')\b(.{0,50})\b/i', $text, $matches)) {
$context = trim($matches[1] ?? '') . ' ' . $matches[2] . ' ' . trim($matches[3] ?? '');
} else {
$context = $text;
}
$law = Law::find($item->law_id);
return [
'id' => $item->id,
'title' => $item->title,
'text' => $context,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
'type' => 'art',
'route' => array_values($this->route($modelClass, $item)),
'category' => optional($law->category)->name,
'law' => $law?->title,
'count_art' => $law->arts->count(),
'count_volums' => $law->volums->count(),
'price' => $law->price,
'image' => $law->image
];
})->toArray();
} else {
$query = $query->where('title', 'LIKE', '%' . ($validated['search'] ?? '') . '%');
}
$items = $query->paginate($validated['per_page'] ?? 10);
return $items->map(function ($item) use ($modelClass) {
$law = Law::find($item?->law_id ?? $item->id);
if ((new $modelClass)->getTable() == 'laws') {
return [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => (new $modelClass)->getTable(),
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
'route' => array_values($this->route($modelClass, $item)),
'category' => optional($law?->category)?->name ?? '',
'image' => $law->image
];
} else if ((new $modelClass)->getTable() == 'art') {
return [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => (new $modelClass)->getTable(),
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
'route' => array_values($this->route($modelClass, $item)),
'law' => $law?->title ?? '',
'image' => $law->image
];
} else {
return [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => (new $modelClass)->getTable(),
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
'route' => array_values($this->route($modelClass, $item)),
'law' => $law?->title ?? '',
];
}
})->toArray();
}
private function route($modelClass, $query)
{
if ((new $modelClass)->getTable() == 'art') {
$route = array_filter([
Law::find($query->law_id)?->title,
Volum::find($query->volum_id)?->title,
Book::find($query->book_id)?->title,
Division::find($query->division_id)?->title,
Section::find($query->section_id)?->title,
Chapter::find($query->chapter_id)?->title,
Part::find($query->part_id)?->title,
Gate::find($query->gate_id)?->title,
Branch::find($query->branch_id)?->title
]);
$route = array_values($route);
return $route;
}
return [];
}
public function fash_search(Request $request)
{
$search = $request->input('search');
$models = [
Law::class,
Art::class
];
$results = [];
foreach ($models as $modelClass) {
$results = array_merge($results, $this->searchModelFastSearch($modelClass, $search));
}
$models_other = [
Volum::class,
Book::class,
Division::class,
Section::class,
Chapter::class,
Part::class,
Gate::class,
Branch::class,
];
$found = false;
foreach ($models_other as $modelClass) {
if (count($this->searchModelFastSearch($modelClass, $search)) > 0 && !$found) {
$results = array_merge($results, $this->searchModelFastSearch($modelClass, $search));
$found = true;
}
}
$models = [
Law::class,
Volum::class,
Book::class,
Division::class,
Section::class,
Chapter::class,
Part::class,
Gate::class,
Branch::class,
Art::class
];
$count_all = 0;
foreach ($models as $modelClass) {
$count_all += count($this->searchModel($modelClass, $search));
}
return $this->success(['items' => $results, 'count' => $count_all]);
}
private function searchModelFastSearch($modelClass, $search)
{
$results = $modelClass::searchLimit($search);
return $results->map(function ($q) use ($modelClass, $search) {
$instance = new $modelClass;
$table = $instance->getTable();
if ($table === 'art') {
return $this->formatArtResult($q, $search);
}
return $this->formatGenericResult($q, $table);
})->toArray();
}
private function formatGenericResult($q, $table)
{
$category = null;
if ($table === 'laws') {
$category = Law::where('id', $q->id)->first()?->category?->name;
} else {
$category = Law::where('id', $q->law_id)->first()?->category?->name;
}
if ($table !== 'laws') {
return [
'id' => $q->id,
'title' => $q->title,
'type' => $table === 'section' ? 'sections' : $table,
'category' => $category,
'law' => Law::where('id', $q->law_id)->first()?->title
];
}
return [
'id' => $q->id,
'title' => $q->title,
'type' => $table === 'section' ? 'sections' : $table,
'category' => $category,
'image' => Law::where('id', $q->id)->first()?->image
];
}
private function formatArtResult($q, $search)
{
$law = Law::where('id', $q->law_id)->first();
$route = array_filter([
$law?->title,
Volum::find($q->volum_id)?->title,
Book::find($q->book_id)?->title,
Division::find($q->division_id)?->title,
Section::find($q->section_id)?->title,
Chapter::find($q->chapter_id)?->title,
Part::find($q->part_id)?->title,
Gate::find($q->gate_id)?->title,
Branch::find($q->branch_id)?->title
]);
$text = $q->text;
$search = preg_quote($search, '/');
if (preg_match('/\b(.{0,50})\b(' . $search . ')\b(.{0,50})\b/i', $text, $matches)) {
$context = trim($matches[1]) . ' ' . $matches[2] . ' ' . trim($matches[3]);
} else {
$context = $text;
}
return [
'id' => $q->id,
'title' => $q->title,
'text' => $context,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : $law->is_locked,
'type' => 'art',
'route' => $route,
'category' => $law?->category?->name,
'law' => $law?->title,
'count_art' => $law->arts->count(),
'count_volum' => $law->volums->count(),
'price' => $law->price,
'image' => $law->image
];
}
private function convertValueTo($var)
{
switch ($var) {
case 1:
return 'hagigi';
break;
case 2:
return 'kifari';
break;
default:
return 'kifari';
break;
}
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Requests\AuthRequest;
use App\Models\User;
use App\Models\UserCode;
use App\Traits\BaseApiResponse;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Http;
class AuthController extends Controller
{
use BaseApiResponse;
public function login(AuthRequest $request)
{
$user = User::query()
->where('mobile', $request->mobile)
->firstOr(function () use ($request) {
return User::create([
'name' => 'Law',
'mobile' => $request->mobile,
'email' => 'law' . $request->mobile . '@law.com',
'password' => Hash::make($request->mobile),
]);
});
$code = random_int(1000, 9999);
UserCode::create([
'user_id' => $user->id,
'code' => $code,
'expired_at' => Carbon::now()->addMinutes(10),
]);
$url = 'https://api.sms.ir/v1/send/verify';
$payload = [
'mobile' => $request->mobile,
'templateId' => '383927',
'parameters' => [
[
'name' => 'CODE',
'value' => strval($code),
],
],
];
$response = Http::withHeaders([
'Content-Type' => 'application/json',
'Accept' => 'text/plain',
'x-api-key' => 'VNXiXc1ERkFUwifxfYFzOIOCjNow9E8as1NpUE5EtkDkaWUlmC09nGxJCFX3kSqD',
])
->post('https://api.sms.ir/v1/send/verify', $payload);
if ($response->successful()) {
return $this->success([], 'موفق', 'کد ورود به شماره موبایل شما ارسال شد');
} else {
return $this->failed([], 'نا موفق', 'در ارسال کد به شماره شما مشکلی وجود دارد');
}
}
public function verify(Request $request)
{
$request->validate([
'mobile' => 'required',
'code' => 'required',
]);
$user = User::where('mobile', $request->mobile)->first();
if (! $user) {
return response()->json(['error' => 'User not found'], 404);
}
$latestCode = UserCode::where('user_id', $user->id)
->where('code', $request->code)
->latest()
->first();
if (! $latestCode) {
return $this->failed([], 'کد ورود اشتباه است', 404);
}
if ($latestCode->code === $request->code) {
$token = $user->createToken('mobile')->plainTextToken;
return $this->success(['token' => $token], 'ورود موفقیت امیز بود');
} else {
return $this->failed([], 'کد ورود اشتباه است', 404);
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Requests\BookRequest;
use App\Models\Book;
use App\Models\Law;
use App\Models\Order;
use App\Traits\BaseApiResponse;
class BookController extends Controller
{
use BaseApiResponse;
public function index(BookRequest $request)
{
$validated = $request->validated();
$perPage = $validatedData['per_page'] ?? 15;
$page = $validatedData['page'] ?? 1;
$books = Book::where('volum_id', $validated['volum_id'])->paginate($perPage, ['*'], 'page', $page);
$books->getCollection()->transform(function ($section) {
$section['is_locked'] = auth()->user()->isSubscriber() !== true ? true : Law::where('is_locked',$section['law_id'])->first()?->is_locked ?? false;
unset($section['law_id']);
unset($section['volum_id']);
return $section;
});
return $this->success($books->items(), 'Success');
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
class CategoriesController extends Controller
{
use BaseApiResponse;
public function index(Request $request)
{
$perPage = $request->input('per_page', 15);
$page = $request->input('page', 1);
$categories = Category::paginate($perPage, ['*'], 'page', $page);
return $this->success($categories->items());
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Requests\ChapterRequest;
use App\Models\Chapter;
use App\Models\Law;
use App\Models\Order;
use App\Traits\BaseApiResponse;
class ChapterController extends Controller
{
use BaseApiResponse;
public function index(ChapterRequest $request)
{
$validated = $request->validated();
$perPage = $validated['per_page'] ?? 15;
$page = $validated['page'] ?? 1;
$chapters = Chapter::where('book_id' , $validated['book_id'])->paginate($perPage, ['*'], 'page', $page);
$chapters->getCollection()->transform(function ($section) {
$section['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $section['law_id'])->first()?->is_locked;
unset($section['law_id']);
unset($section['section_id']);
return $section;
});
return $this->success($chapters->items());
}
}

View File

@@ -0,0 +1,151 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\Folder;
use App\Models\FolderArt;
use App\Models\Law;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
class FolderController extends Controller
{
use BaseApiResponse;
public function index()
{
$folder = Folder::query()->where('user_id', auth()->id())->get()
->map(function ($q) {
return [
"id" => $q->id,
"name" => $q->name,
"count_of_arts" => $q->arts->count(),
"created_at" => $q->created_at,
];
});
return $this->success($folder);
}
public function create(Request $request)
{
$validted = $request->validate([
'name' => 'required'
]);
Folder::create([
'user_id' => auth()->user()->id,
'name' => $validted['name']
]);
return $this->success([], 'ایجاد شد', 'پوشه با موفقیت ایجاد شد.');
}
public function assign(Request $request)
{
$validted = $request->validate([
'folder_id' => 'required',
'art_id' => 'required'
]);
if (Folder::query()->where('id', $validted['folder_id'])->count() == 0) {
return $this->failed([], 'پوشه مورد نظر یافت نشد', 404);
}
if (FolderArt::query()->where('folder_id', $validted['folder_id'])->where('art_id', $validted['art_id'])->count() > 0) {
return $this->failed([], 'ارت مورد نظر قبلا اضافه شده است', 400);
}
FolderArt::create([
'folder_id' => $validted['folder_id'],
'art_id' => $validted['art_id']
]);
return $this->success([], 'اضافه شد', 'ارت با موفیت اضافه شد');
}
public function folder($id)
{
$arts = FolderArt::where('folder_id', $id)
->with('arts.chapter', 'arts.part', 'arts.volum', 'arts.law', 'arts.book', 'arts.section', 'arts.gate')
->get()
->pluck('arts')
->flatten();
$arts = $arts->map(function ($art) {
$text = $art->text ?? '';
$shortText = '';
if (strlen($text) > 50) {
$shortText = substr($text, 0, 50);
$shortText = substr($shortText, 0, strrpos($shortText, ' ')) . '...';
} else {
$shortText = $text;
}
return [
'id' => $art->id,
'title' => $art->title,
'text' => $shortText,
'number' => $art->number,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $art->law->id)->first()?->is_locked,
'chapter' => $art->chapter != null ? [
'id' => $art->chapter->id,
'title' => $art->chapter->title,
'number' => $art->chapter->number,
] : null,
'part' => $art->part != null ? [
'id' => $art->part->id,
'title' => $art->part->title,
'number' => $art->part->number,
] : null,
'volum' => $art->volum != null ? [
'id' => $art->volum->id,
'title' => $art->volum->title,
'number' => $art->volum->number,
] : null,
'law' => $art->law != null ? [
'id' => $art->law->id,
'title' => $art->law->title,
'number' => $art->law->number,
] : null,
'book' => $art->book != null ? [
'id' => $art->book->id,
'title' => $art->book->title,
'number' => $art->book->number,
] : null,
'section' => $art->section != null ? [
'id' => $art->section->id,
'title' => $art->section->title,
'number' => $art->section->number,
] : null,
'gate' => $art->gate != null ? [
'id' => $art->gate->id,
'title' => $art->gate->title,
'number' => $art->gate->number,
] : null,
];
});
return $this->success($arts);
}
public function delete_folder($id)
{
if (Folder::query()->where('id', $id)->count() == 0) {
return $this->failed('پوشه یافت نشد', 'پوشه مورد نظر یافت نشد', 404);
}
Folder::query()->where('id', $id)->delete();
return $this->success([], 'حذف شد', 'پوشه با موفقیت حذف شد');
}
public function delete_art($id,$art_id)
{
if (FolderArt::query()->where('folder_id', $id)->where('art_id', $art_id)->count() == 0) {
return $this->failed([], 'ارت مورد نظر یافت نشد', 404);
}
FolderArt::query()->where('folder_id', $id)->where('art_id', $art_id)->delete();
return $this->success([], 'حذف شد', 'ارت با موفقیت حذف شد');
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Requests\ChapterRequest;
use App\Models\Gate;
use App\Models\Law;
use App\Models\Order;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
class GateController extends Controller
{
use BaseApiResponse;
public function index(ChapterRequest $request)
{
$validated = $request->validated();
$gates = Gate::where('book_id', $validated['book_id'])
->paginate($validated['per_page'], ['*'], 'page', $validated['page']);
$gates->getCollection()->transform(function ($gate) {
unset($gate['book_id']);
$gate['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $gate['law_id'])->first()?->is_locked;
unset($gate['law_id']);
return $gate;
});
return $this->success($gates->items());
}
}

View File

@@ -0,0 +1,131 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
// 1. IMPORT THE JOB WE CREATED
use App\Jobs\CheckBazaarSubscription;
// These are your existing imports
use App\Models\Law;
use App\Models\Notification;
use App\Models\RecentArt;
use App\Models\UserSubscriber;
use App\Traits\BaseApiResponse;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class HomeController extends Controller
{
use BaseApiResponse;
public function index()
{
$user = auth()->user();
// 2. DISPATCH THE JOB AT THE VERY BEGINNING
// ===================================================================
// Find the user's latest subscription that has a purchase token
$latestSubscription = $user->userSubscribers()->whereNotNull('purchase_token')->latest()->first();
// If such a subscription exists, create a new job and hand it to the queue
// if ($latestSubscription) {
// CheckBazaarSubscription::dispatch($latestSubscription);
// }
// ===================================================================
// Your API now continues immediately without waiting for the check to finish.
// --- ALL THE REST OF YOUR CODE REMAINS EXACTLY THE SAME ---
$recent = RecentArt::query()->where('user_id', $user->id)->get()->map(function ($q) {
return [
'id' => $q->law?->id,
'name' => $q->law?->title,
'is_locked' => $q->law?->is_locked
];
});
$laws = Law::orderBy('created_at')->get()->map(function ($q) {
return [
'id' => $q->id,
'name' => $q->title,
'is_locked' => $q->is_locked
];
});
$categories = ['hagigi', 'kifari'];
$lawsByCategory = [];
foreach ($categories as $category) {
$lawsByCategory[$category] = Law::whereHas('category', function ($q) use ($category) {
$q->where('type', $category);
})->get()->map(function ($q) {
return [
"id" => $q->id,
"title" => $q->title,
"is_locked" => $q->is_locked,
"category_id" => $q->category_id,
"price" => $q->price,
"image" => $q->image,
"type" => 'law'
];
});
}
$free_law = Law::where('is_locked', false)->orderBy('created_at')->get()->map(function ($q) {
return [
'id' => $q->id,
'name' => $q->title,
'is_locked' => $q->is_locked
];
});
$current_plan = null;
$freeSubscription = $user->userSubscribers()
->whereHas('subscribe', function ($query) {
$query->where('is_free', true);
})
->where('expired_at', '>=', now())
->first();
$expiredAt = null;
$current_plan = null;
if ($freeSubscription) {
$expiredAt = $freeSubscription->expired_at;
$current_plan = [
'id' => $freeSubscription->id,
'name' => $freeSubscription->subscribe->name,
'price' => $freeSubscription->subscribe->price,
'expired_day' => $freeSubscription->expired_at->diffInDays(now()),
'is_free' => true
];
}
$latestSubscription = $user->userSubscribers()->latest()->first();
$expiredDays = UserSubscriber::query()->where('user_id', $user->id)->where('expired_at', '>=', now())->get()->sum(function ($subscriber) {return $subscriber->expired_at->diffInDays(now());});
$purchase_token = $latestSubscription?->purchase_token;
$current_plan = [
'id' => $latestSubscription->id,
'name' => $latestSubscription->subscribe->name ?? 'Subscription',
'price' => $latestSubscription->subscribe->price ?? 100,
'expired_day' => $expiredDays,
'is_free' => false
];
$unread_notifications_count = Notification::unreadForUser($user->id)->count();
return $this->success([
'recent' => $recent,
'laws' => $lawsByCategory,
'last_law' => $laws,
'free' => $free_law,
'current_plan' => $current_plan,
'unread_notifications_count' => $unread_notifications_count,
]);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\Law;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
class LawController extends Controller
{
use BaseApiResponse;
public function index(Request $request)
{
$perPage = $request->input('per_page', 15);
$page = $request->input('page', 1);
$laws = Law::simplePaginate($perPage, ['*'], 'page', $page);
return $this->success($laws->items(), 'Success');
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\Note;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
class NoteController extends Controller
{
use BaseApiResponse;
public function create(Request $request)
{
$validated = $request->validate([
'art_id' => 'required',
'note' => 'required',
'color_code' => 'nullable'
]);
Note::query()->create(
[
'user_id' => auth()->user()->id,
'art_id' => $validated['art_id'],
'note' => $validated['note'],
'color_code' => $validated['color_code'],
]
);
return $this->success([], 'successfully created.');
}
public function update($id, Request $request)
{
$validated = $request->validate([
'note' => 'required',
'color_code' => 'nullable'
]);
$note = Note::findOrFail($id);
$note->update([
'note' => $validated['note'],
'color_code' => $validated['color_code'],
]);
return $this->success([], 'successfully updated.');
}
public function destroy($id)
{
$note = Note::findOrFail($id);
$note->delete();
return $this->success([], 'successfully deleted.');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\Notification;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
use BaseApiResponse;
public function index(Request $request)
{
$user = auth()->user();
$all = Notification::query()->latest()->get();
$now = now();
foreach ($all as $notification) {
$user->notifications()->syncWithoutDetaching([
$notification->id => ['read_at' => $now],
]);
}
$notifications = $all->map(function ($notification) {
return [
'id' => $notification->id,
'title' => $notification->title,
'description' => $notification->description,
'created_at' => $notification->created_at->toIso8601String(),
'is_read' => true,
];
});
return $this->success([
'notifications' => $notifications,
]);
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Requests\ChapterRequest;
use App\Models\Law;
use App\Models\Order;
use App\Models\Part;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
class PartController extends Controller
{
use BaseApiResponse;
public function index(ChapterRequest $request)
{
$validated = $request->validated();
$perPage = $request->input('per_page', 15);
$page = $request->input('page', 1);
$parts = Part::where('book_id' , $request->input('book_id'))->paginate($perPage, ['*'], 'page', $page);
$parts->getCollection()->transform(function ($part) {
unset($part['book_id']);
$gate['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $part['law_id'])->first()?->is_locked;
unset($gate['law_id']);
return $gate;
});
return $this->success($parts->items());
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\Order;
use App\Models\PaymentTransaction;
use App\Models\SubscribePlan;
use App\Models\UserSubscriber;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Shetabit\Multipay\Invoice;
use Shetabit\Payment\Facade\Payment;
class PayController extends Controller
{
use BaseApiResponse;
public function pay(Request $request)
{
$validation = $request->validate([
'subscribe_plan_id' => 'required|exists:subscribe_plans,id',
]);
$subscribePlan = SubscribePlan::findOrFail($request->subscribe_plan_id);
try {
$invoice = (new Invoice)->amount($subscribePlan->price);
$callback = 'https://ghaafapp.ir';
$payment = Payment::callbackUrl($callback . '/payment/callback')
->purchase($invoice, function ($driver, $transaction_id) use ($subscribePlan) {
PaymentTransaction::create([
'user_id' => auth()->user()->id,
'subscribe_plan_id' => $subscribePlan->id,
'transaction_id' => $transaction_id,
'amount' => $subscribePlan->price,
'status' => 'pending',
]);
})
->pay();
return $this->success(['url' => $payment]);
} catch (\Exception $e) {
Log::error('Payment initiation failed: ' . $e->getMessage());
return $this->failed('Payment initialization failed', $e->getMessage());
}
}
public function callback(Request $request)
{
try {
$url = 'http://bitpay.ir/payment/gateway-result-second';
$api = '066fd-d622e-690a9-be618-ddf02bc6059bbbd67c317bb340d1';
$trans_id = $request->input('trans_id');
$id_get = $request->input('id_get');
$result = $this->get($url, $api, $trans_id, $id_get);
$parseDecode = json_decode($result);
if ($parseDecode->status == 1) {
$transaction = PaymentTransaction::where('transaction_id', $id_get)->first();
$transaction->update([
'status' => 'success',
]);
$expiredAt = now()->addDays($transaction->subscribePlan->expired_day);
UserSubscriber::where('user_id', $transaction->user_id)->delete();
$transaction->user->userSubscribers()->create([
'subscribe_plan_id' => $transaction->subscribe_plan_id,
'expired_at' => $expiredAt,
]);
return $this->success([], 'Payment Successful', 'Subscription successfully activated.');
}
return $this->failed([], ['title' => 'Payment Failed', 'message' => 'Payment verification failed.']);
} catch (\Exception $e) {
Log::info('error in callback function', ['error' => $e->getMessage()]);
return $this->failed([], ['title' => 'Payment Failed', 'message' => 'Payment verification failed.']);
}
}
private function send($url, $api, $amount, $redirect, $factorId, $name, $email, $description)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, "api=$api&amount=$amount&redirect=$redirect&factorId=$factorId&name=$name&email=$email&description=$description");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
private function get($url, $api, $trans_id, $id_get)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, "api=$api&id_get=$id_get&trans_id=$trans_id&json=1");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Requests\SectionRequest;
use App\Models\Law;
use App\Models\LikeSection;
use App\Models\Order;
use App\Models\Section;
use App\Traits\BaseApiResponse;
class SectionController extends Controller
{
use BaseApiResponse;
public function index(SectionRequest $request)
{
$validatedData = $request->validated();
$perPage = $validatedData['per_page'] ?? 15;
$page = $validatedData['page'] ?? 1;
$section = Section::where('book_id', $validatedData['book_id'])->paginate($perPage, ['*'], 'page', $page);
$section->getCollection()->transform(function ($section) {
unset($section['book_id']);
$section['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked',$section['law_id'])->first()?->is_locked;
unset($section['law_id']);
return $section;
});
return $this->success($section->items(), 'Success');
}
public function like(Section $section)
{
$userId = auth()->id();
$existingLike = LikeSection::query()->where('section_id', $section->id)
->where('user_id', $userId)
->first();
if ($existingLike) {
$existingLike->delete();
return $this->success(null, 'Success', 'Section unliked successfully');
}
LikeSection::create([
'section_id' => $section->id,
'user_id' => $userId,
]);
return $this->success(null, 'Success', 'Section liked successfully');
}
}

View File

@@ -0,0 +1,275 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\PaymentTransaction;
use App\Models\SubscribePlan;
use App\Models\UserSubscriber;
use App\Traits\BaseApiResponse;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Shetabit\Multipay\Invoice;
use Shetabit\Payment\Facade\Payment;
class SubscribePlanController extends Controller
{
use BaseApiResponse;
public function index()
{
$subscribePlans = SubscribePlan::query()->where('is_active', true)->get()->map(function ($q) {
if ($q->is_free) {
if (auth()->user()->subscribePlans()->first() !== null) {
return null;
}
}
return [
'id' => $q->id,
'name' => $q->name,
'price' => $q->price,
'expired_day' => $q->expired_day,
'is_free' => $q->is_free == 1 ? true : false,
'type' => $q->type,
'transaction' => $q->transaction
];
})->filter(function ($q) {
return $q != null;
});
return $this->success(array_values($subscribePlans->toArray()), 'Subscribe Plan', 'Subscribe Plan List');
}
public function subscribe(Request $request)
{
$request->validate([
'subscribe_plan_id' => 'required|exists:subscribe_plans,id',
]);
$subscribePlan = SubscribePlan::findOrFail($request->subscribe_plan_id);
$user = auth()->user();
$activeSubscription = $user->userSubscribers()
->where('expired_at', '>', now())
->first();
if ($activeSubscription && !$activeSubscription?->subscribe?->is_free && !$subscribePlan->is_free) {
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'You already have an active subscription. Please wait until it expires.']);
}
if ($subscribePlan->is_free) {
$hasUsedFreePlan = $user->userSubscribers()
->whereHas('subscribe', function ($query) {
$query->where('is_free', true);
})->exists();
if ($hasUsedFreePlan) {
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'You have already used the free plan.']);
}
$expiredAt = now()->addDays($subscribePlan->expired_day + 1);
$user->userSubscribers()->create([
'subscribe_plan_id' => $subscribePlan->id,
'expired_at' => $expiredAt,
]);
return $this->success(null, 'Subscribe Plan', 'Free Subscribe Plan Successfully Activated');
}
try {
$invoice = (new Invoice)->amount($subscribePlan->price);
$callback = 'https://ghaafapp.ir';
$payment = Payment::callbackUrl($callback)
->purchase($invoice, function ($driver, $transaction_id) use ($subscribePlan) {
PaymentTransaction::create([
'user_id' => auth()->user()->id,
'subscribe_plan_id' => $subscribePlan->id,
'transaction_id' => $transaction_id,
'amount' => $subscribePlan->price,
'status' => 'pending',
]);
})
->pay();
return $this->success(['url' => $payment]);
} catch (\Exception $e) {
Log::error('Payment initiation failed: ' . $e->getMessage());
return $this->failed(null, 'درگاه پرداخت در دسترس نیست');
}
}
public function subscribe_new(Request $request)
{
$package_name_bazzar = 'com.razzaghi.lawbook.android';
$request->validate([
'subscribe_plan_id' => 'required|exists:subscribe_plans,id',
'subscription_id' => 'nullable',
'purchase_token' => 'nullable'
]);
$subscribePlan = SubscribePlan::findOrFail($request->subscribe_plan_id);
$user = auth()->user();
$activeSubscription = $user->userSubscribers()
->where('expired_at', '>', now())
->latest('expired_at')
->first();
if ($subscribePlan->is_free) {
$hasUsedFreePlan = $user->userSubscribers()
->whereHas('subscribe', function ($query) {
$query->where('is_free', true);
})
->exists();
if ($hasUsedFreePlan) {
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'You have already used the free plan.']);
}
$expiredAt = $activeSubscription ? $activeSubscription->expired_at->addDays($subscribePlan->expired_day) : now()->addDays($subscribePlan->expired_day);
$user->userSubscribers()->create([
'subscribe_plan_id' => $subscribePlan->id,
'expired_at' => $expiredAt,
'is_free' => true
]);
return $this->success(null, 'Subscribe Plan', 'Free Subscribe Plan Successfully Activated');
}
$subscription_id = $request->input('subscription_id');
$purchase_token = $request->input('purchase_token');
if (!$subscription_id || !$purchase_token) {
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Invalid subscription details.']);
}
$url = "https://pardakht.cafebazaar.ir/devapi/v2/api/applications/$package_name_bazzar/subscriptions/$subscription_id/purchases/$purchase_token";
$client = new \GuzzleHttp\Client();
try {
$response = $client->get($url, [
'headers' => [
'CAFEBAZAAR-PISHKHAN-API-SECRET' => 'eyJhbGciOiJIUzI1NiIsImtpZCI6ImFuY2llbnQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJuYXNoZXItcGlzaGtoYW4tYXBpIiwiaWF0IjoxNzQwMjQ3NTMzLCJleHAiOjQ4OTM4NDc1MzMsImFwaV9hZ2VudF9pZCI6MzQ2NX0.UCrr3IHxCqn77ckxfnaubrsyCfrhPm18gJgyg1qNqwA',
]
]);
$data = json_decode($response->getBody(), true);
if (!isset($data['validUntilTimestampMsec']) || $data['validUntilTimestampMsec'] < now()->timestamp * 1000) {
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Invalid or expired subscription.']);
}
$bazaarExpiredAt = Carbon::createFromTimestampMs($data['validUntilTimestampMsec']);
$expiredAt = $activeSubscription ? $activeSubscription->expired_at->addDays($subscribePlan->expired_day) : $bazaarExpiredAt;
$user->userSubscribers()->whereHas('subscribe', function ($query) {
$query->where('is_free', true);
})
->update(['expired_at' => now()]);
$user->userSubscribers()->create([
'subscribe_plan_id' => $subscribePlan->id,
'expired_at' => $expiredAt,
'subscription_id' => $subscription_id,
'purchase_token' => $purchase_token,
'is_free' => false
]);
return $this->success(null, 'Subscribe Plan', 'Subscription successfully activated.');
} catch (\Exception $e) {
Log::error('Error in subscription', ['Error' => $e->getMessage()]);
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'Failed to verify subscription.']);
}
}
public function paymentCallback(Request $request)
{
try {
$url = 'http://bitpay.ir/payment/gateway-result-second';
$api = '066fd-d622e-690a9-be618-ddf02bc6059bbbd67c317bb340d1';
$trans_id = $request->input('trans_id');
$id_get = $request->input('id_get');
$result = $this->get($url, $api, $trans_id, $id_get);
$parseDecode = json_decode($result);
if ($parseDecode->status == 1) {
$transaction = PaymentTransaction::where('transaction_id', $id_get)->firstOrFail();
$transaction->update([
'status' => 'success',
]);
$expiredAt = now()->addDays($transaction->subscribePlan->expired_day);
UserSubscriber::where('user_id', $transaction->user_id)->delete();
$transaction->user->userSubscribers()->create([
'subscribe_plan_id' => $transaction->subscribe_plan_id,
'expired_at' => $expiredAt,
]);
return $this->success([], 'Payment Successful', 'Subscription successfully activated.');
}
return $this->failed([], ['title' => 'Payment Failed', 'message' => 'Payment verification failed.']);
} catch (\Exception $e) {
return $this->failed([], ['title' => 'Payment Failed', 'message' => 'Payment verification failed.']);
}
}
public function current()
{
$user = auth()->user();
$subscribePlans = UserSubscriber::where('user_id', $user->id)
->where('expired_at', '>', now())
->orderBy('expired_at', 'desc')
->get();
if ($subscribePlans->isNotEmpty()) {
$totalExpiredDays = $subscribePlans->sum('expired_day');
$latestPlan = $subscribePlans->first();
$subscribePlanData = [
'id' => $latestPlan->id,
'name' => $latestPlan->subscribe->name,
'price' => $latestPlan->subscribe->price,
'expired_day' => $totalExpiredDays,
'is_free' => $latestPlan->subscribe->is_free == 1,
'expired_at' => Carbon::now()->addDays($totalExpiredDays)->format('Y-m-d'),
];
return $this->success($subscribePlanData, 'Subscribe Plan', 'Current Subscribe Plan');
}
return $this->success(null, 'Subscribe Plan', 'No Subscribe Plan');
}
private function send($url, $api, $amount, $redirect, $factorId, $name, $email, $description)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, "api=$api&amount=$amount&redirect=$redirect&factorId=$factorId&name=$name&email=$email&description=$description");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
private function get($url, $api, $trans_id, $id_get)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, "api=$api&id_get=$id_get&trans_id=$trans_id&json=1");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Requests\VersionRequest;
use App\Models\Version;
use App\Traits\BaseApiResponse;
class VersionController extends Controller
{
use BaseApiResponse;
public function index(VersionRequest $versionRequest)
{
$version = Version::query()->where('type', $versionRequest->type)->orderBy('id', 'desc')->first();
if (!$version) {
return $this->failed([], 'Version not found');
}
if (intval($version->number) > $versionRequest->number) {
return $this->success([
'force_update' => $version->force_update == 1 ? true : false
], 'Your app need to be updated');
}
return $this->success([
'force_update' => false
], 'Version successfully');
}
}

View File

@@ -0,0 +1,864 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Requests\CheckBookFilterRequest;
use App\Http\Requests\CheckBookRequest;
use App\Http\Requests\VolumRequest;
use App\Models\Art;
use App\Models\Book;
use App\Models\Branch;
use App\Models\Category;
use App\Models\Chapter;
use App\Models\Division;
use App\Models\Gate;
use App\Models\Law;
use App\Models\Order;
use App\Models\Part;
use App\Models\RecentArt;
use App\Models\Section;
use App\Models\Volum;
use App\Traits\BaseApiResponse;
class VolumController extends Controller
{
use BaseApiResponse;
public function index(VolumRequest $request)
{
$validatedData = $request->validated();
$perPage = $validatedData['per_page'] ?? 15;
$page = $validatedData['page'] ?? 1;
$volumes = Volum::where('law_id', $validatedData['law_id'])->paginate($perPage, ['*'], 'page', $page);
$volumes->getCollection()->transform(function ($volume) {
$volume['has_book'] = Book::where('volum_id', $volume->id)->exists();
$volume['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $volume['law_id'])->first()?->is_locked;
unset($volume['law_id']);
return $volume;
});
return $this->success($volumes->items(), 'Success');
}
public function check(CheckBookRequest $request)
{
$bookId = $request->book_id;
$volumeId = $request->volume_id;
$law_Id = $request->law_id;
$section_id = $request->section_id;
$division_id = $request->division_id;
$part_id = $request->part_id;
$branch_id = $request->branch_id;
$chapter_id = $request->chapter_id;
$gate_id = $request->gate_id;
$perPage = $request->per_page ?? 10;
if ($bookId) {
$book = Book::with(['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])
->find($bookId);
if (!$book) {
return $this->success([], 'Book not found');
}
$data = [];
$foundRelation = false;
foreach (['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'] as $relation) {
if ($book->{$relation}->count() > 0) {
$foundRelation = true;
$items = $book->{$relation}()->paginate($perPage);
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => $relation,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
$paginationData = [
'next_page_url' => $items->nextPageUrl(),
];
break;
}
}
if ($foundRelation) {
return $this->success($data, 'Success');
} else {
return $this->success([], 'No relations found');
}
}
if ($division_id) {
$division = Division::with(['sections', 'chapters', 'parts', 'gate', 'branch', 'art'])
->find($division_id);
if (!$division) {
return $this->success([], 'Division not found');
}
$data = [];
$foundRelation = false;
foreach (['sections', 'chapters', 'parts', 'gate', 'branch', 'art'] as $relation) {
if ($division->{$relation}->count() > 0) {
$foundRelation = true;
$items = $division->{$relation}()->paginate($perPage);
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => $relation,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
break;
}
}
if ($foundRelation) {
return $this->success($data, 'Success');
} else {
return $this->success([], 'No relations found');
}
}
if ($section_id) {
$section = Section::with(['chapters', 'parts', 'gate', 'branch', 'art'])
->find($section_id);
if (!$section) {
return $this->success([], 'Section not found');
}
$data = [];
$foundRelation = false;
foreach (['chapters', 'parts', 'gate', 'branch', 'art'] as $relation) {
if ($section->{$relation}->count() > 0) {
$foundRelation = true;
$items = $section->{$relation}()->paginate($perPage);
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => $relation,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
break;
}
}
if ($foundRelation) {
return $this->success($data, 'Success');
} else {
return $this->success([], 'No relations found');
}
}
if ($volumeId) {
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])
->find($volumeId);
if (!$volume) {
return $this->success([], 'Volume not found');
}
$data = [];
$foundRelation = false;
foreach (['book', 'divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'art'] as $relation) {
if ($volume->{$relation}->count() > 0) {
$foundRelation = true;
$items = $volume->{$relation}()->paginate($perPage);
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => $relation,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
break;
}
}
if ($foundRelation) {
return $this->success($data, 'Success');
} else {
return $this->success([], 'No relations found');
}
}
if ($part_id) {
$part = Part::with(['gate', 'branch', 'art'])
->find($part_id);
if (!$part) {
return $this->success([], 'Part not found');
}
$data = [];
$foundRelation = false;
foreach (['gate', 'branch', 'art'] as $relation) {
if ($part->{$relation}->count() > 0) {
$foundRelation = true;
$items = $part->{$relation}()->paginate($perPage);
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => $relation,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
break;
}
}
if ($foundRelation) {
return $this->success($data, 'Success');
} else {
return $this->success([], 'No relations found');
}
}
if ($chapter_id) {
$chapter = Chapter::with(['parts', 'gate', 'branch', 'art'])
->find($chapter_id);
if (!$chapter) {
return $this->success([], 'Chapter not found');
}
$data = [];
$foundRelation = false;
foreach (['parts', 'gate', 'branch', 'art'] as $relation) {
if ($chapter->{$relation}->count() > 0) {
$foundRelation = true;
$items = $chapter->{$relation}()->paginate($perPage);
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => $relation,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
break;
}
}
if ($foundRelation) {
return $this->success($data, 'Success');
} else {
return $this->success([], 'No relations found');
}
}
if ($branch_id) {
$branch = Branch::with(['art'])
->find($branch_id);
if (!$branch) {
return $this->success([], 'Branch not found');
}
$data = [];
$foundRelation = false;
foreach (['art'] as $relation) {
if ($branch->{$relation}->count() > 0) {
$foundRelation = true;
$items = $branch->{$relation}()->paginate($perPage);
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => $relation,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
break;
}
}
if ($foundRelation) {
return $this->success($data, 'Success');
} else {
return $this->success([], 'No relations found');
}
}
if ($gate_id) {
$gate = Gate::with(['branch', 'art'])
->find($gate_id);
if (!$gate) {
return $this->success([], 'Gate not found');
}
$data = [];
$foundRelation = false;
foreach (['branch', 'art'] as $relation) {
if ($gate->{$relation}->count() > 0) {
$foundRelation = true;
$items = $gate->{$relation}()->paginate($perPage);
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => $relation,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
break;
}
}
if ($foundRelation) {
return $this->success($data, 'Success');
} else {
return $this->success([], 'No relations found');
}
}
if ($volumeId) {
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs'])
->find($volumeId);
if (!$volume) {
return $this->success([], 'Volume not found');
}
$data = [];
$foundRelation = false;
foreach (['book', 'divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs'] as $relation) {
if ($volume->{$relation}->count() > 0) {
$foundRelation = true;
$items = $volume->{$relation}()->paginate($perPage);
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => $relation,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
break;
}
}
if ($foundRelation) {
return $this->success($data, 'Success');
} else {
return $this->success([], 'No relations found');
}
}
if ($law_Id) {
$law = Law::find($law_Id);
if (!$law) {
return $this->success([], 'Law not found');
}
$arts = Volum::query()
->where('law_id', $law->id)
->get();
RecentArt::query()->updateOrCreate([
'user_id' => auth()->user()->id,
'law_id' => $law_Id
], [
'user_id' => auth()->user()->id,
'law_id' => $law_Id
]);
$data = [];
if (count($arts) > 0) {
foreach ($arts as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => 'volume',
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
return $this->success($data, 'Success');
}
$data = [];
$arts = Art::query()
->where('law_id', $law->id)
->where('section_id', null)
->where('gate_id', null)
->where('part_id', null)
->where('chapter_id', null)
->where('book_id', null)
->where('volum_id', null)
->get();
foreach ($arts as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => 'art',
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked
];
}
return $this->success($data, 'Success');
}
return $this->success([], 'No law or book or volume specified');
}
public function check_filter(CheckBookFilterRequest $request)
{
$filters = [
'category_id' => [
'model' => Law::class,
'foreign_key' => 'category_id',
'type' => (new Law)->getTable(),
'check_mode' => Volum::class,
'check_key' => 'law_id',
],
'law_id' => [
'model' => Volum::class,
'foreign_key' => 'law_id',
'type' => (new Volum)->getTable(),
'check_mode' => Book::class,
'check_key' => 'volum_id',
],
'volume_id' => [
'model' => Book::class,
'foreign_key' => 'volum_id',
'type' => (new Book)->getTable(),
'check_mode' => Division::class,
'check_key' => 'book_id',
],
'book_id' => [
'model' => Division::class,
'foreign_key' => 'book_id',
'type' => (new Division)->getTable(),
'check_mode' => Section::class,
'check_key' => 'division_id',
],
'division_id' => [
'model' => Section::class,
'foreign_key' => 'division_id',
'type' => 'sections',
'check_mode' => Chapter::class,
'check_key' => 'section_id',
],
'section_id' => [
'model' => Chapter::class,
'foreign_key' => 'section_id',
'type' => (new Chapter)->getTable(),
'check_mode' => Part::class,
'check_key' => 'chapter_id',
],
'chapter_id' => [
'model' => Part::class,
'foreign_key' => 'chapter_id',
'type' => (new Part)->getTable(),
'check_mode' => Gate::class,
'check_key' => 'part_id',
],
'part_id' => [
'model' => Gate::class,
'foreign_key' => 'part_id',
'type' => (new Gate)->getTable(),
'check_mode' => Branch::class,
'check_key' => 'gate_id',
],
'gate_id' => [
'model' => Branch::class,
'foreign_key' => 'gate_id',
'type' => (new Branch)->getTable(),
'check_mode' => Art::class,
'check_key' => 'branch_id',
],
'branch_id' => [
'model' => Art::class,
'foreign_key' => 'branch_id',
'type' => (new Art)->getTable(),
'check_mode' => Art::class,
'check_key' => 'branch_id'
]
];
foreach ($filters as $filterKey => $filterInfo) {
$filterValue = $request->get($filterKey);
if ($filterValue) {
$model = $filterInfo['model'];
$foreignKey = $filterInfo['foreign_key'];
$type = $filterInfo['type'];
$check_model = $filterInfo['check_mode'];
$check_key = $filterInfo['check_key'];
$items = $model::where($foreignKey, $filterValue)->paginate(10);
if ($filterKey === 'category_id') {
$items = $model::whereIn('category_id', Category::where('type', $this->convertValueTo($filterValue))->get()->pluck('id'))->paginate(10);
}
if ($foreignKey == 'branch_id') {
return $this->success([], '');
}
$data = $items->map(function ($item) use ($type, $check_model, $check_key) {
return [
'id' => $item?->id,
'title' => $item?->title,
'number' => $item?->number,
'type' => $type,
'is_end' => $check_model::where($check_key, $item?->id)->count() !== 0 ? false : true
];
});
return $this->success($data, 'Success');
}
}
return $this->success([], 'No law or book or volume specified');
}
public function check_filter_with_art(CheckBookFilterRequest $request)
{
$lawId = $request->law_id;
$bookId = $request->book_id;
$volumeId = $request->volume_id;
$sectionId = $request->section_id;
$divisionId = $request->division_id;
$partId = $request->part_id;
$branchId = $request->branch_id;
$chapterId = $request->chapter_id;
$gateId = $request->gate_id;
$categoryId = $request->category_id;
$perPage = $request->per_page ?? 10;
if ($categoryId) {
$categories = Category::with(['laws'])->where('type', $this->convertValueTo($categoryId))->get()->pluck('id');
$items = Law::query()->whereIn('category_id', $categories)->get();
$data = [];
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => 'laws',
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked,
'image' => $item?->image,
'law' => $item?->title,
'count_art' => $item->arts->count(),
'count_volums' => $item->volums->count(),
'price' => $item->price,
];
}
return $this->success($data, 'Success');
}
if ($lawId) {
$law = Law::with(['volums', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'arts'])->find($lawId);
if (!$law) {
return $this->success([], 'Law not found');
}
$data = $this->checkRelations($law, ['volums', 'book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'arts'], $perPage);
if ($data) {
return $this->success($data, 'Success');
}
return $this->success([], 'No related records found in the law');
}
if ($bookId) {
$book = Book::with(['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])->find($bookId);
if (!$book) {
return $this->success([], 'Book not found');
}
$data = $this->checkRelations($book, ['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'], $perPage);
if ($data) {
return $this->success($data, 'Success');
}
return $this->success([], 'No related records found in the book');
}
if ($volumeId) {
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])->find($volumeId);
if (!$volume) {
return $this->success([], 'Volume not found');
}
$data = $this->checkRelations($volume, ['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'], $perPage);
if ($data) {
return $this->success($data, 'Success');
}
return $this->success([], 'No related records found in the volume');
}
if ($sectionId) {
$section = Section::with(['gates', 'parts', 'chapters', 'branchs', 'art'])->find($sectionId);
if (!$section) {
return $this->success([], 'Section not found');
}
$data = $this->checkRelations($section, ['gates', 'parts', 'chapters', 'branchs', 'art'], $perPage);
if ($data) {
return $this->success($data, 'Success');
}
return $this->success([], 'No related records found in the section');
}
if ($divisionId) {
$division = Division::with(['gates', 'parts', 'chapters', 'branchs', 'art'])->find($divisionId);
if (!$division) {
return $this->success([], 'Division not found');
}
$data = $this->checkRelations($division, ['gates', 'parts', 'chapters', 'branchs', 'art'], $perPage);
if ($data) {
return $this->success($data, 'Success');
}
return $this->success([], 'No related records found in the division');
}
if ($partId) {
$part = Part::with(['gates', 'art'])->find($partId);
if (!$part) {
return $this->success([], 'Part not found');
}
$data = $this->checkRelations($part, ['gates', 'art'], $perPage);
if ($data) {
return $this->success($data, 'Success');
}
return $this->success([], 'No related records found in the part');
}
if ($branchId) {
$branch = Branch::with(['gates', 'chapters', 'art'])->find($branchId);
if (!$branch) {
return $this->success([], 'Branch not found');
}
$data = $this->checkRelations($branch, ['gates', 'chapters', 'art'], $perPage);
if ($data) {
return $this->success($data, 'Success');
}
return $this->success([], 'No related records found in the branch');
}
if ($chapterId) {
$chapter = Chapter::with(['gate', 'parts', 'art'])->find($chapterId);
if (!$chapter) {
return $this->success([], 'Chapter not found');
}
$data = $this->checkRelations($chapter, ['gate', 'parts', 'art'], $perPage);
if ($data) {
return $this->success($data, 'Success');
}
return $this->success([], 'No related records found in the chapter');
}
if ($gateId) {
$gate = Gate::with(['art'])->find($gateId);
if (!$gate) {
return $this->success([], 'Gate not found');
}
$data = $this->checkRelations($gate, ['art'], $perPage);
if ($data) {
return $this->success($data, 'Success');
}
return $this->success([], 'No related records found in the gate');
}
return $this->success([], 'No valid filter specified');
}
private function prepareItemsData($items, $type)
{
$data = [];
foreach ($items as $item) {
$law = Law::find($item->law_id);
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => $type,
'route' => $this->route($item, $item),
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('is_locked', $item->law_id)->first()?->is_locked,
'law' => $law?->title,
'image' => $law?->image,
'count_art' => $law?->arts?->count() ?? 0,
'count_volums' => $law?->volums?->count() ?? 0,
'price' => $law?->price,
];
}
return $data;
}
private function checkRelations($model, $relations, $perPage)
{
foreach ($relations as $relation) {
if ($model->{$relation} && $model->{$relation}->count() > 0) {
$items = $model->{$relation}()->paginate($perPage);
return $this->prepareItemsData($items, $relation);
}
}
return null;
}
private function convertValueTo($var)
{
switch ($var) {
case 1:
return 'hagigi';
break;
case 2:
return 'kifari';
break;
default:
return 'kifari';
break;
}
}
private function route($modelClass, $query)
{
$route = [];
switch ((new $modelClass)->getTable()) {
case 'laws':
$route = array_filter([
Law::find($query->id)?->title
]);
break;
case 'volums':
$route = array_filter([
Law::find($query->law_id)?->title,
Volum::find($query->id)?->title
]);
break;
case 'books':
$route = array_filter([
Law::find($query->law_id)?->title,
Volum::find($query->volum_id)?->title,
]);
break;
case 'divisions':
$route = array_filter([
Law::find($query->law_id)?->title,
Volum::find($query->volum_id)?->title,
Book::find($query->book_id)?->title,
]);
break;
case 'sections':
$route = array_filter([
Law::find($query->law_id)?->title,
Volum::find($query->volum_id)?->title,
Book::find($query->book_id)?->title,
Division::find($query->division_id)?->title,
]);
break;
case 'chapters':
$route = array_filter([
Law::find($query->law_id)?->title,
Volum::find($query->volum_id)?->title,
Book::find($query->book_id)?->title,
Division::find($query->division_id)?->title,
Section::find($query->section_id)?->title,
]);
break;
case 'parts':
$route = array_filter([
Law::find($query->law_id)?->title,
Volum::find($query->volum_id)?->title,
Book::find($query->book_id)?->title,
Division::find($query->division_id)?->title,
Section::find($query->section_id)?->title,
Chapter::find($query->chapter_id)?->title,
]);
break;
case 'gates':
$route = array_filter([
Law::find($query->law_id)?->title,
Volum::find($query->volum_id)?->title,
Book::find($query->book_id)?->title,
Division::find($query->division_id)?->title,
Section::find($query->section_id)?->title,
Chapter::find($query->chapter_id)?->title,
Part::find($query->part_id)?->title,
]);
break;
case 'branches':
$route = array_filter([
Law::find($query->law_id)?->title,
Volum::find($query->volum_id)?->title,
Book::find($query->book_id)?->title,
Division::find($query->division_id)?->title,
Section::find($query->section_id)?->title,
Chapter::find($query->chapter_id)?->title,
Part::find($query->part_id)?->title,
Gate::find($query->gate_id)?->title,
]);
break;
case 'art':
$route = array_filter([
Law::find($query->law_id)?->title,
Volum::find($query->volum_id)?->title,
Book::find($query->book_id)?->title,
Division::find($query->division_id)?->title,
Section::find($query->section_id)?->title,
Chapter::find($query->chapter_id)?->title,
Part::find($query->part_id)?->title,
Gate::find($query->gate_id)?->title,
Branch::find($query->branch_id)?->title,
]);
break;
default:
$route = [];
break;
}
return array_values($route);
}
}