Introduce option model for storing necessary configuration data.
This commit is contained in:
33
app/Http/Controllers/Api/OptionController.php
Normal file
33
app/Http/Controllers/Api/OptionController.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Option;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class OptionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
return response()->json(Option::all(['name', 'value']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
foreach ($request->all() as $key => $value) {
|
||||
$option = Option::firstOrNew(['name' => $key]);
|
||||
|
||||
$option->value = $value;
|
||||
$option->save();
|
||||
}
|
||||
return response()->json($request->all());
|
||||
}
|
||||
}
|
||||
16
app/Http/Controllers/OptionController.php
Normal file
16
app/Http/Controllers/OptionController.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class OptionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
return view('option.index');
|
||||
}
|
||||
}
|
||||
19
app/Models/Option.php
Normal file
19
app/Models/Option.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Option extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'value',
|
||||
];
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user