You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
2.9 KiB
119 lines
2.9 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\System;
|
|
|
|
use App\Traits\Authorizable;
|
|
use App\Models\Currency;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
class CurrencyController extends Controller
|
|
{
|
|
use Authorizable;
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$result = Currency::latest()->paginate();
|
|
return view('currency.index', compact('result'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('currency.new');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$this->validate($request, [
|
|
'name' => 'required|max:255',
|
|
'symbol' => 'required|max:8'
|
|
]);
|
|
|
|
Currency::create($request->only('name', 'symbol', 'description', 'decimal_length', 'actived') + ['created_by' => Auth::user()->id]);
|
|
|
|
flash('Currency has been added');
|
|
|
|
return redirect()->back();
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param \App\Currency $post
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(Currency $currency)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Currency $post
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(Currency $currency)
|
|
{
|
|
$currency = Currency::findOrFail($currency->id);
|
|
|
|
return view('currency.edit', compact('currency'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \App\Currency $post
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, Currency $currency)
|
|
{
|
|
$this->validate($request, [
|
|
'name' => 'required|max:255',
|
|
'symbol' => 'required|max:8'
|
|
]);
|
|
|
|
$currency = Currency::findOrFail($currency->id);
|
|
$currency->updated_by = Auth::user()->id;
|
|
$currency->update($request->all());
|
|
|
|
flash()->success('Currency has been updated.');
|
|
|
|
return redirect()->route('currency.index');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Currency $post
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(Currency $currency)
|
|
{
|
|
$currency = Currency::findOrFail($currency->id);
|
|
$currency->updated_by = Auth::user()->id;
|
|
$currency->delete();
|
|
|
|
flash()->success('Currency has been deleted.');
|
|
|
|
return redirect()->route('currency.index');
|
|
}
|
|
}
|
|
|