Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

class AdminController extends Controller
{
public function __construct()
protected $userService;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line after the variable declarations.

public function __construct(UserService $user)
{
$this->userService = $user;
$this->middleware('auth');
}
/**
Expand All @@ -30,16 +32,10 @@ public function index()
*
* @return \Illuminate\Http\Response
*/

public function ban(User $user)
{

if ($user->is_banned) {
$user->is_banned = 0;
} else {
$user->is_banned = 1;
}
$user->update();

$this->userService->banUnban($user);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make two separate methods for ban and unban.

return redirect()->back()->with('success', 'User Status Changed');
}

Expand All @@ -48,6 +44,7 @@ public function delete(User $user)
$user->delete();
return redirect()->back()->with('success', 'User Deleted');
}

public function create()
{
return view('admin.user.add');
Expand All @@ -59,9 +56,10 @@ public function create()
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(ProfileRequest $request, UserService $action)

public function store(ProfileRequest $request)
{
$action->storeUser($request);
$this->userService->storeUser($request);
return redirect()->back()->with('success', 'Librarian Added');
}

Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/AuthorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function edit(Author $author)
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request, Author $author)
{
//
}
Expand All @@ -87,6 +87,5 @@ public function destroy(Author $author)
{
$author->delete();
return redirect()->back()->with('success', 'Author Deleted');

}
}
1 change: 0 additions & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ public function profileUpdate(ProfileRequest $request, UserService $action)
$action->updateUser($request, $profile);
return redirect()->back()->with('success', 'Profile updated');
}

}
3 changes: 2 additions & 1 deletion app/Models/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class Author extends Model
{
use HasFactory,SoftDeletes;
use HasFactory;
use SoftDeletes;

public const PAGINATE = 5;
public function books()
Expand Down
10 changes: 10 additions & 0 deletions app/Services/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ public function storeUser($request)
$user->password = Hash::make($request->password);
$user->save();
}

public function banUnban($user)
{
if ($user->is_banned) {
$user->is_banned = 0;
} else {
$user->is_banned = 1;
}
$user->update();
}
}
9 changes: 6 additions & 3 deletions resources/views/admin/author/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<div class="card-body">
<h4 class="card-title">Add Author</h4>

<form class="forms-sample" action="{{route('author.update')}}" method="post" enctype="multipart/form-data">
<form class="forms-sample" action="{{route('author.update',$author)}}" method="post" enctype="multipart/form-data">
@csrf
@method('PUT')

<div class="form-group row">
<label for="name" class="col-sm-3 col-form-label">Name</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="name" name="name" value="{{$auther->name}}" placeholder="Username">
<input type="text" class="form-control" id="name" name="name" value="{{$author->name}}" placeholder="Username">
@if($errors->has("name"))
<div class="alert alert-danger" role="alert">
{{$errors->first('name')}}
Expand All @@ -34,11 +34,14 @@
@endif

</div>
<div class="bg-indigo-300">
<img class="object-contain h-48 w-full" src="{{asset('/').$author->image}}">
</div>
</div>
<div class="form-group row">
<label for="description" class="col-sm-3 col-form-label">Description</label>
<div class="col-sm-9">
<textarea name="description" class="form-control" id="description" cols="30" rows="10">value="{{$auther->description}}"</textarea>
<textarea name="description" class="form-control" id="description" cols="30" rows="10">{{$author->description}}</textarea>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/author/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
@csrf
@method("DELETE")
</form>
<a href="{{route('author.edit', $author->id)}}" class="inline-flex items-center px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-white-200 bg-teal-300 hover:bg-gray-50 hover:no-underline focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
<a href="{{route('author.edit', $author)}}" class="inline-flex items-center px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-white-200 bg-teal-300 hover:bg-gray-50 hover:no-underline focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
<!-- Heroicon name: pencil -->
<svg class="-ml-1 mr-2 h-5 w-5 text-gray-500"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"
Expand Down