Init(Core): Change repo
This commit is contained in:
500
app/Http/Controllers/api/ArtController.php
Normal file
500
app/Http/Controllers/api/ArtController.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
96
app/Http/Controllers/api/AuthController.php
Normal file
96
app/Http/Controllers/api/AuthController.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
app/Http/Controllers/api/BookController.php
Normal file
36
app/Http/Controllers/api/BookController.php
Normal 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');
|
||||
}
|
||||
}
|
||||
24
app/Http/Controllers/api/CategoriesController.php
Normal file
24
app/Http/Controllers/api/CategoriesController.php
Normal 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());
|
||||
}
|
||||
}
|
||||
37
app/Http/Controllers/api/ChapterController.php
Normal file
37
app/Http/Controllers/api/ChapterController.php
Normal 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());
|
||||
}
|
||||
}
|
||||
151
app/Http/Controllers/api/FolderController.php
Normal file
151
app/Http/Controllers/api/FolderController.php
Normal 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([], 'حذف شد', 'ارت با موفقیت حذف شد');
|
||||
}
|
||||
}
|
||||
37
app/Http/Controllers/api/GateController.php
Normal file
37
app/Http/Controllers/api/GateController.php
Normal 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());
|
||||
}
|
||||
}
|
||||
131
app/Http/Controllers/api/HomeController.php
Normal file
131
app/Http/Controllers/api/HomeController.php
Normal 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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
23
app/Http/Controllers/api/LawController.php
Normal file
23
app/Http/Controllers/api/LawController.php
Normal 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');
|
||||
}
|
||||
}
|
||||
58
app/Http/Controllers/api/NoteController.php
Normal file
58
app/Http/Controllers/api/NoteController.php
Normal 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.');
|
||||
}
|
||||
}
|
||||
41
app/Http/Controllers/api/NotificationController.php
Normal file
41
app/Http/Controllers/api/NotificationController.php
Normal 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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
38
app/Http/Controllers/api/PartController.php
Normal file
38
app/Http/Controllers/api/PartController.php
Normal 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());
|
||||
}
|
||||
}
|
||||
109
app/Http/Controllers/api/PayController.php
Normal file
109
app/Http/Controllers/api/PayController.php
Normal 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;
|
||||
}
|
||||
}
|
||||
59
app/Http/Controllers/api/SectionController.php
Normal file
59
app/Http/Controllers/api/SectionController.php
Normal 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');
|
||||
}
|
||||
}
|
||||
275
app/Http/Controllers/api/SubscribePlanController.php
Normal file
275
app/Http/Controllers/api/SubscribePlanController.php
Normal 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;
|
||||
}
|
||||
}
|
||||
32
app/Http/Controllers/api/VersionController.php
Normal file
32
app/Http/Controllers/api/VersionController.php
Normal 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');
|
||||
}
|
||||
}
|
||||
864
app/Http/Controllers/api/VolumController.php
Normal file
864
app/Http/Controllers/api/VolumController.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user