Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add notifications in medicine and accounts #3

Merged
merged 1 commit into from
Jun 11, 2023
Merged
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
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