diff --git a/app/Http/Controllers/API/AppController.php b/app/Http/Controllers/API/AppController.php new file mode 100644 index 0000000..5a1aa54 --- /dev/null +++ b/app/Http/Controllers/API/AppController.php @@ -0,0 +1,27 @@ +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); + } +} diff --git a/app/Http/Controllers/AppController.php b/app/Http/Controllers/AppController.php index 23c3dec..22d04b9 100644 --- a/app/Http/Controllers/AppController.php +++ b/app/Http/Controllers/AppController.php @@ -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.")); } } diff --git a/app/Http/Requests/App/SubmitRequest.php b/app/Http/Requests/App/SubmitRequest.php new file mode 100644 index 0000000..2050b76 --- /dev/null +++ b/app/Http/Requests/App/SubmitRequest.php @@ -0,0 +1,32 @@ +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' + ]; + } +} diff --git a/resources/views/app/index.blade.php b/resources/views/app/index.blade.php index f9aee25..0b9e347 100644 --- a/resources/views/app/index.blade.php +++ b/resources/views/app/index.blade.php @@ -10,13 +10,33 @@
-
+ @if (session()->has('status')) +
{{ session()->get('status') }}
+ @endif + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif + + @csrf + @for ($i = 1; $i <= 3; $i++)
- - + @foreach ($directories as $folder) + + @endforeach
+ @endfor +
+ +
diff --git a/routes/api.php b/routes/api.php index e4a0cf5..d5cc472 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,5 +1,6 @@ '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']); diff --git a/routes/web.php b/routes/web.php index 1d58276..2711a0b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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']);