Add App Config API Call
This commit is contained in:
parent
c329ceb486
commit
6759f613c8
6 changed files with 114 additions and 6 deletions
27
app/Http/Controllers/API/AppController.php
Normal file
27
app/Http/Controllers/API/AppController.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\ApiResponseResource;
|
||||
use App\Models\Directories;
|
||||
use App\Models\Setting;
|
||||
|
||||
class AppController extends Controller
|
||||
{
|
||||
/**
|
||||
* get App Config
|
||||
* @return ApiResponseResource
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$response = [];
|
||||
$settings = Setting::orWhere('key', 'Button1')->orWhere('key', 'Button2')->orWhere('key', 'Button3')->get();
|
||||
|
||||
foreach ($settings as $setting) {
|
||||
$response['folders'][$setting->key] = Directories::find($setting->value)->only('id', 'name');
|
||||
}
|
||||
|
||||
return new ApiResponseResource("OK", $response);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\App\SubmitRequest;
|
||||
use App\Models\Directories;
|
||||
use App\Models\Setting;
|
||||
|
||||
class AppController extends Controller
|
||||
{
|
||||
|
|
@ -13,6 +15,30 @@ class AppController extends Controller
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('app.index');
|
||||
$button_1 = Setting::where('key', 'Button1')->first()->only('value');
|
||||
$button_2 = Setting::where('key', 'Button2')->first()->only('value');
|
||||
$button_3 = Setting::where('key', 'Button3')->first()->only('value');
|
||||
|
||||
return view('app.index', [
|
||||
'directories' => Directories::where('parent', \null)->where('id', '<>', 1)->orderBy('order', 'ASC')->get(),
|
||||
'button_1' => \intval($button_1['value']),
|
||||
'button_2' => \intval($button_2['value']),
|
||||
'button_3' => \intval($button_3['value'])
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit
|
||||
*
|
||||
* @param \App\Http\Requests\App\SubmitRequest $request
|
||||
* @return redirect
|
||||
*/
|
||||
public function submit(SubmitRequest $request)
|
||||
{
|
||||
Setting::where('key', 'Button1')->update(['value' => $request->button_1]);
|
||||
Setting::where('key', 'Button2')->update(['value' => $request->button_2]);
|
||||
Setting::where('key', 'Button3')->update(['value' => $request->button_3]);
|
||||
|
||||
return redirect()->route('app.index')->with('status', __("Configuration sauvegardée."));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
32
app/Http/Requests/App/SubmitRequest.php
Normal file
32
app/Http/Requests/App/SubmitRequest.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\App;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SubmitRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'button_1' => 'required|exists:directories,id',
|
||||
'button_2' => 'required|exists:directories,id',
|
||||
'button_3' => 'required|exists:directories,id'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -10,13 +10,33 @@
|
|||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<form action="">
|
||||
@if (session()->has('status'))
|
||||
<div class="alert alert-success">{{ session()->get('status') }}</div>
|
||||
@endif
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
<form action="{{ route('app.submit') }}" method="POST">
|
||||
@csrf
|
||||
@for ($i = 1; $i <= 3; $i++)
|
||||
<div class="form-group">
|
||||
<label>{{ __("Bouton") }} 1</label>
|
||||
<select name="button_1" class="form-control">
|
||||
<option value="1">Toto</option>
|
||||
<label>{{ __("Bouton") }} {{ $i }}</label>
|
||||
<select name="button_{{ $i }}" class="form-control" required>
|
||||
@foreach ($directories as $folder)
|
||||
<option value="{{ $folder->id }}" @if($folder->id === ${"button_" . $i}) selected @endif>{{ json_decode($folder->name)->fr }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@endfor
|
||||
<div class="form-group text-center">
|
||||
<input type="submit" class="btn btn-primary" value="{{ __("Sauvegarder") }}">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\API\AppController;
|
||||
use App\Http\Controllers\API\SettingsController;
|
||||
use App\Http\Controllers\API\SyncController;
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ use App\Http\Controllers\API\SyncController;
|
|||
|
||||
Route::group(['middleware' => 'api.token'], function () {
|
||||
Route::get('settings', [SettingsController::class, 'get']);
|
||||
Route::get('app', [AppController::class, 'get']);
|
||||
|
||||
Route::get('users', [SyncController::class, 'getUsers']);
|
||||
Route::post('contacts', [SyncController::class, 'getContacts']);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ Route::middleware('auth')->group(function () {
|
|||
Route::post('/show/updateStatus', [ShowController::class, 'updateStatus']);
|
||||
|
||||
Route::get('/app', [AppController::class, 'index'])->name('app.index');
|
||||
Route::post('/app', [AppController::class, 'submit'])->name('app.submit');
|
||||
|
||||
Route::middleware('can:is-admin')->group(function () {
|
||||
Route::resource('setting', SettingController::class)->except(['create', 'store', 'show', 'destroy']);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue