git commit "add dynamic settings management"
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\SettingStoreRequest;
|
||||
use App\Http\Requests\Admin\SettingUpdateRequest;
|
||||
use App\Models\Setting;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$settings = Setting::query()
|
||||
->applySearch()
|
||||
->paginate(10);
|
||||
|
||||
return view('admin.settings.index', compact('settings'));
|
||||
}
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
$settings = Setting::all();
|
||||
return view('admin.settings.create',compact('settings'));
|
||||
|
||||
}
|
||||
|
||||
public function store(SettingStoreRequest $request)
|
||||
{
|
||||
Setting::create($request->validated());
|
||||
|
||||
return redirect()->route('admin.settings.index');
|
||||
}
|
||||
|
||||
public function edit(Setting $setting)
|
||||
{
|
||||
return view('admin.settings.edit', compact('setting'));
|
||||
|
||||
}
|
||||
|
||||
public function update(SettingUpdateRequest $request,Setting $setting)
|
||||
{
|
||||
|
||||
$setting->update($request->validated());
|
||||
|
||||
return redirect()
|
||||
->route('admin.settings.index')
|
||||
->with('success', 'تنظیمات با موفقیت ویرایش شد.');
|
||||
|
||||
}
|
||||
|
||||
public function destroy(Setting $setting)
|
||||
{
|
||||
$setting->delete();
|
||||
|
||||
return redirect()
|
||||
->route('admin.settings.index')
|
||||
->with('success', 'محصول با موفقیت حذف شد.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SettingStoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'code'=>[
|
||||
'required',
|
||||
'string',
|
||||
'max:100'
|
||||
],
|
||||
'value'=>[
|
||||
'nullable',
|
||||
'string',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SettingUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'code'=>[
|
||||
'required',
|
||||
'string',
|
||||
'max:100'
|
||||
],
|
||||
'value'=>[
|
||||
'nullable',
|
||||
'string',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user