Skip to content

Commit

Permalink
PBMS-6: fixing-controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
soulaimaneyahya committed Dec 28, 2024
1 parent de38c51 commit 5b6ed9c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 161 deletions.
26 changes: 17 additions & 9 deletions app/Http/Controllers/Authors/AuthorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Http\Controllers\Authors;

use App\Models\Author;
use Illuminate\View\View;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use App\Http\Requests\StoreAuthorRequest;
use App\Http\Requests\UpdateAuthorRequest;

Expand All @@ -12,7 +14,7 @@ class AuthorController extends Controller
/**
* Display a listing of the resource.
*/
public function index()
public function index(): View
{
$authors = Author::all();

Expand All @@ -22,47 +24,53 @@ public function index()
/**
* Show the form for creating a new resource.
*/
public function create()
public function create(): View
{
return view('authors.create');
}

/**
* Store a newly created resource in storage.
*/
public function store(StoreAuthorRequest $request)
public function store(StoreAuthorRequest $request): RedirectResponse
{
//
$validatedData = $request->validated();
Author::create($validatedData);

return redirect()->route('authors.index')->with('success', 'Author created successfully.');
}

/**
* Display the specified resource.
*/
public function show(Author $author)
public function show(Author $author): View
{
return view('authors.show', compact('author'));
}

/**
* Show the form for editing the specified resource.
*/
public function edit(Author $author)
public function edit(Author $author): View
{
return view('authors.edit', compact('author'));
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateAuthorRequest $request, Author $author)
public function update(UpdateAuthorRequest $request, Author $author): RedirectResponse
{
//
$validatedData = $request->validated();
$author->update($validatedData);

return redirect()->route('authors.index')->with('success', 'Author updated successfully.');
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Author $author)
public function destroy(Author $author): RedirectResponse
{
$author->delete();

Expand Down
26 changes: 17 additions & 9 deletions app/Http/Controllers/Books/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Http\Controllers\Books;

use App\Models\Book;
use Illuminate\View\View;
use Illuminate\Http\RedirectResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreBookRequest;
use App\Http\Requests\UpdateBookRequest;
Expand All @@ -12,7 +14,7 @@ class BookController extends Controller
/**
* Display a listing of the resource.
*/
public function index()
public function index(): View
{
$books = Book::all();

Expand All @@ -22,47 +24,53 @@ public function index()
/**
* Show the form for creating a new resource.
*/
public function create()
public function create(): View
{
return view('books.create');
}

/**
* Store a newly created resource in storage.
*/
public function store(StoreBookRequest $request)
public function store(StoreBookRequest $request): RedirectResponse
{
//
$validatedData = $request->validated();
Book::create($validatedData);

return redirect()->route('books.index')->with('success', 'Book created successfully.');
}

/**
* Display the specified resource.
*/
public function show(Book $book)
public function show(Book $book): View
{
return view('books.show', compact('book'));
}

/**
* Show the form for editing the specified resource.
*/
public function edit(Book $book)
public function edit(Book $book): View
{
return view('books.edit', compact('book'));
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateBookRequest $request, Book $book)
public function update(UpdateBookRequest $request, Book $book): RedirectResponse
{
//
$validatedData = $request->validated();
$book->update($validatedData);

return redirect()->route('books.index')->with('success', 'Book updated successfully.');
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Book $book)
public function destroy(Book $book): RedirectResponse
{
$book->delete();

Expand Down
67 changes: 0 additions & 67 deletions app/Http/Controllers/Books/BookDetailsController.php

This file was deleted.

26 changes: 17 additions & 9 deletions app/Http/Controllers/Categories/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Http\Controllers\Categories;

use App\Models\Category;
use Illuminate\View\View;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use App\Http\Requests\StoreCategoryRequest;
use App\Http\Requests\UpdateCategoryRequest;

Expand All @@ -12,7 +14,7 @@ class CategoryController extends Controller
/**
* Display a listing of the resource.
*/
public function index()
public function index(): View
{
$categories = Category::all();

Expand All @@ -22,47 +24,53 @@ public function index()
/**
* Show the form for creating a new resource.
*/
public function create()
public function create(): View
{
return view('categories.create');
}

/**
* Store a newly created resource in storage.
*/
public function store(StoreCategoryRequest $request)
public function store(StoreCategoryRequest $request): RedirectResponse
{
//
$validatedData = $request->validated();
Category::create($validatedData);

return redirect()->route('categories.index')->with('success', 'Category created successfully.');
}

/**
* Display the specified resource.
*/
public function show(Category $category)
public function show(Category $category): View
{
return view('categories.show', compact('category'));
}

/**
* Show the form for editing the specified resource.
*/
public function edit(Category $category)
public function edit(Category $category): View
{
return view('categories.edit', compact('category'));
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateCategoryRequest $request, Category $category)
public function update(UpdateCategoryRequest $request, Category $category): RedirectResponse
{
//
$validatedData = $request->validated();
$category->update($validatedData);

return redirect()->route('categories.index')->with('success', 'Category updated successfully.');
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Category $category)
public function destroy(Category $category): RedirectResponse
{
$category->delete();

Expand Down
67 changes: 0 additions & 67 deletions app/Http/Controllers/Images/ImageController.php

This file was deleted.

0 comments on commit 5b6ed9c

Please sign in to comment.