You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.5 KiB
PHTML

1 year ago
<?php
namespace App\Http\Controllers;
use App\Models\Account;
use Illuminate\Http\Request;
class AccountController extends Controller
{
public function index()
{
$query = Account::orderBy('updated_at', 'desc')->paginate();
return inertia('Account/Index', [
'query' => $query,
1 year ago
]);
}
public function create()
{
return inertia('Account/Form');
}
1 year ago
public function store(Request $request)
{
$request->validate([
'name' => 'required|string',
'bank_name' => 'required|string',
'holder_name' => 'required|string',
'account_number' => 'required|string',
'logo' => 'required|image',
1 year ago
]);
$file = $request->file('logo');
$file->store('uploads', 'public');
1 year ago
Account::create([
'name' => $request->name,
'bank_name' => $request->bank_name,
'holder_name' => $request->holder_name,
'account_number' => $request->account_number,
'logo' => $file->hashName('uploads'),
1 year ago
]);
return redirect()->route('account.index')
->with('message', ['type' => 'success', 'message' => 'Item has been saved']);
}
public function edit(Account $account)
{
return inertia('Account/Form', [
'account' => $account
]);
1 year ago
}
public function update(Request $request, Account $account)
{
$request->validate([
'name' => 'required|string',
'bank_name' => 'required|string',
'holder_name' => 'required|string',
'account_number' => 'required|string',
'logo' => 'nullable|image',
1 year ago
]);
if ($request->hasFile('logo')) {
$file = $request->file('logo');
$file->store('uploads', 'public');
$account->fill(['logo' => $file->hashName('uploads')]);
}
1 year ago
$account->update([
'name' => $request->name,
'bank_name' => $request->bank_name,
'holder_name' => $request->holder_name,
'account_number' => $request->account_number,
]);
return redirect()->route('account.index')
->with('message', ['type' => 'success', 'message' => 'Item has been updated']);
1 year ago
}
public function destroy(Account $account)
{
$account->delete();
session()->flash('message', ['type' => 'success', 'message' => 'Item has been deleted']);
}
}