-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed validation, models folder and added seeders
- Loading branch information
1 parent
1bafe40
commit 642772b
Showing
47 changed files
with
606 additions
and
283 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
...tp/Controllers/Admin/AuthorController.php → ...rollers/Api/V1/Admin/AuthorController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...Http/Controllers/Admin/BookController.php → ...ntrollers/Api/V1/Admin/BookController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...ttp/Controllers/Admin/GenreController.php → ...trollers/Api/V1/Admin/GenreController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...tp/Controllers/Admin/ReportController.php → ...rollers/Api/V1/Admin/ReportController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1; | ||
|
||
use App\Models\Book; | ||
use App\Http\Resources\BookResource; | ||
use Illuminate\Support\Facades\Cookie; | ||
|
||
class BookController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
return BookResource::collection(Book::with(['authors']) | ||
->when(request('search'), function ($query) { | ||
$search = request('search'); | ||
//Cookie::queue('search', $search); | ||
$query->where('title', 'LIKE', "%{$search}%") | ||
->orWhereHas('authors', function($query) use ($search){ | ||
$query->where('author', 'LIKE', "%{$search}%"); | ||
}); | ||
}) | ||
->isApproved()->latest()->get()); | ||
} | ||
|
||
public function show(Book $book) | ||
{ | ||
return BookResource::collection($book->with('reviews')->latest()->take(5)->get()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
app/Http/Controllers/Controller.php → app/Http/Controllers/Api/V1/Controller.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 3 additions & 9 deletions
12
app/Http/Controllers/HomeController.php → ...ttp/Controllers/Api/V1/HomeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Book; | ||
namespace App\Http\Controllers\Api\V1; | ||
use App\Models\Book; | ||
|
||
class HomeController extends Controller | ||
{ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth'); | ||
} | ||
|
||
public function index() | ||
{ | ||
$books = Book::select('is_approved')->get(); | ||
$approved_book_count = $books->where('is_approved', true)->count(); | ||
$pending_book_count = $books->whereNull('is_approved')->count(); | ||
$rejected_book_count = $books->where('is_approved', false)->whereNotNull('is_approved')->count(); | ||
return view('home', compact('approved_book_count', 'pending_book_count', 'rejected_book_count')); | ||
return [$approved_book_count, $pending_book_count, $rejected_book_count]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1\User; | ||
|
||
use App\Http\Controllers\Api\V1\Controller; | ||
use App\Models\Report; | ||
use App\Models\Book; | ||
|
||
class ReportController extends Controller | ||
{ | ||
public function store(Book $book){ | ||
if(Report::where('book_id', $book->id)->where('user_id', auth()->id())->exists()){ | ||
return redirect()->route('books.show', $book)->with('error', 'This book is already reported'); | ||
} | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
...ttp/Controllers/User/ReviewController.php → ...trollers/Api/V1/User/ReviewController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...tp/Controllers/User/SettingController.php → ...rollers/Api/V1/User/SettingController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class BookResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function toArray($request) | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'title' => $this->title, | ||
'description' => $this->description, | ||
'cover_image_url' => $this->cover_image_url, | ||
'price' => $this->price, | ||
'discount' => $this->discount | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.