Skip to content

Commit

Permalink
Merge pull request #3 from alfikiafan/hafidh
Browse files Browse the repository at this point in the history
add notifications in medicine and accounts
  • Loading branch information
hafidhmuhammadakbar authored Jun 11, 2023
2 parents c05a0f7 + c3b8146 commit 4cc3b3b
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 9 deletions.
18 changes: 13 additions & 5 deletions app/Http/Controllers/MedicineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ public function store(Request $request)

$validatedData['discount'] = $validatedData['discount'] / 100;

Medicine::create($validatedData);
$success = Medicine::create($validatedData);

return redirect()->route('medicines.index')->with('success', 'Obat berhasil ditambahkan');
if ($success) {
return redirect()->route('medicines.index')->with('success', 'Medicine add successfully');
} else {
return redirect()->route('medicines.create')->withErrors('Medicine failed to add');
}
}

public function create()
Expand All @@ -68,9 +72,13 @@ public function update(Request $request, Medicine $medicine)

$validatedData['discount'] = $validatedData['discount'] / 100;

$medicine->update($validatedData);

return redirect()->route('medicines.index')->with('success', 'Medicine updated successfully');
$success = $medicine->update($validatedData);

if ($success) {
return redirect()->route('medicines.index')->with('success', 'Medicine updated successfully');
} else {
return redirect()->route('medicines.edit')->withErrors('Medicine failed to add');
}
}

public function destroy(Medicine $medicine)
Expand Down
17 changes: 13 additions & 4 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ public function store(Request $request)
'joining_date' => 'required|date',
]);

User::create($request->all());
$success = User::create($request->all());

return redirect()->route('accounts.index')->with('success', 'User created successfully');
if (!$success) {
return redirect()->route('accounts.index')->with('success', 'User add successfully');
}
else{
return redirect()->route('accounts.create')->withErrors('User failed to add');
}
}

public function edit(User $user)
Expand All @@ -59,9 +64,13 @@ public function update(Request $request, User $user)
'role' => 'required',
]);

$user->update($request->all());
$success = $user->update($request->all());

return redirect()->route('accounts.index')->with('success', 'User updated successfully');
if ($success) {
return redirect()->route('accounts.index')->with('success', 'User updated successfully');
} else {
return redirect()->route('accounts.edit', $user->id)->withErrors('User failed to update');
}
}

public function destroy(User $user)
Expand Down
10 changes: 10 additions & 0 deletions resources/views/accounts/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

@section('content')
<div class="container-fluid pt-4 px-5">
{{-- if error to add accounts --}}
@if ($errors->any())
<div class="alert alert-danger">
<ul class="mb-0">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="row">
<div class="col-12">
<div class="card border shadow-xs mb-4">
Expand Down
10 changes: 10 additions & 0 deletions resources/views/accounts/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

@section('content')
<div class="container-fluid py-4 px-5">
{{-- if error to edit accounts --}}
@if ($errors->any())
<div class="alert alert-danger">
<ul class="mb-0">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="row">
<div class="col-12">
<div class="card border shadow-xs mb-4">
Expand Down
6 changes: 6 additions & 0 deletions resources/views/accounts/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

@section('content')
<div class="container-fluid py-4 px-5">
{{-- if add or edit success --}}
@if(session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
<div class="row">
<div class="col-12">
<div class="card border shadow-xs mb-4">
Expand Down
10 changes: 10 additions & 0 deletions resources/views/medicines/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

@section('content')
<div class="container-fluid pt-4 px-5">
{{-- if error to add medicine --}}
@if ($errors->any())
<div class="alert alert-danger">
<ul class="mb-0">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="row">
<div class="col-12">
<div class="card border shadow-xs mb-4">
Expand Down
10 changes: 10 additions & 0 deletions resources/views/medicines/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

@section('content')
<div class="container-fluid py-4 px-5">
{{-- if error to edit medicines --}}
@if ($errors->any())
<div class="alert alert-danger">
<ul class="mb-0">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="row">
<div class="col-12">
<div class="card border shadow-xs mb-4">
Expand Down
6 changes: 6 additions & 0 deletions resources/views/medicines/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

@section('content')
<div class="container-fluid py-4 px-5">
{{-- if add or edit success --}}
@if(session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
<div class="row">
<div class="col-12">
<div class="card border shadow-xs mb-4">
Expand Down

0 comments on commit 4cc3b3b

Please sign in to comment.