From 6254d885baff1bdb2a7efcf3ee39422f2af98096 Mon Sep 17 00:00:00 2001 From: Mosaab Emam Date: Mon, 9 Jan 2023 13:12:49 +0000 Subject: [PATCH] feat: Implement route-model binding by default --- .../api/controller/model/controller.blade.php | 17 ++++------------ .../model/controller_resource.blade.php | 17 ++++------------ views/api/docs/controller/destroy.blade.php | 2 +- views/api/docs/controller/show.blade.php | 2 +- views/api/docs/controller/update.blade.php | 2 +- .../scaffold/controller/controller.blade.php | 20 ++++--------------- 6 files changed, 15 insertions(+), 45 deletions(-) diff --git a/views/api/controller/model/controller.blade.php b/views/api/controller/model/controller.blade.php index e96f7a5e8..ba7db315d 100644 --- a/views/api/controller/model/controller.blade.php +++ b/views/api/controller/model/controller.blade.php @@ -57,11 +57,8 @@ public function store(Create{{ $config->modelNames->name }}APIRequest $request): } {!! $docShow !!} - public function show($id): JsonResponse + public function show({{ $config->modelNames->name }} ${{ $config->modelNames->camel }}): JsonResponse { - /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */ - ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id); - if (empty(${{ $config->modelNames->camel }})) { @if($config->options->localized) return $this->sendError( @@ -83,11 +80,8 @@ public function show($id): JsonResponse } {!! $docUpdate !!} - public function update($id, Update{{ $config->modelNames->name }}APIRequest $request): JsonResponse + public function update({{ $config->modelNames->name }} ${{ $config->modelNames->camel }}, Update{{ $config->modelNames->name }}APIRequest $request): JsonResponse { - /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */ - ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id); - if (empty(${{ $config->modelNames->camel }})) { @if($config->options->localized) return $this->sendError( @@ -112,11 +106,8 @@ public function update($id, Update{{ $config->modelNames->name }}APIRequest $req } {!! $docDestroy !!} - public function destroy($id): JsonResponse + public function destroy({{ $config->modelNames->name }} ${{ $config->modelNames->camel }}): JsonResponse { - /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */ - ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id); - if (empty(${{ $config->modelNames->camel }})) { @if($config->options->localized) return $this->sendError( @@ -131,7 +122,7 @@ public function destroy($id): JsonResponse @if($config->options->localized) return $this->sendResponse( - $id, + ${{ $config->modelNames->camel }}->id, __('messages.deleted', ['model' => __('models/{{ $config->modelNames->camelPlural }}.singular')]) ); @else diff --git a/views/api/controller/model/controller_resource.blade.php b/views/api/controller/model/controller_resource.blade.php index e90f383b1..a5b8aaede 100644 --- a/views/api/controller/model/controller_resource.blade.php +++ b/views/api/controller/model/controller_resource.blade.php @@ -58,11 +58,8 @@ public function store(Create{{ $config->modelNames->name }}APIRequest $request): } {!! $docShow !!} - public function show($id): JsonResponse + public function show({{ $config->modelNames->name }} ${{ $config->modelNames->camel }}): JsonResponse { - /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */ - ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id); - if (empty(${{ $config->modelNames->camel }})) { @if($config->options->localized) return $this->sendError( @@ -84,11 +81,8 @@ public function show($id): JsonResponse } {!! $docUpdate !!} - public function update($id, Update{{ $config->modelNames->name }}APIRequest $request): JsonResponse + public function update({{ $config->modelNames->name }} ${{ $config->modelNames->camel }}, Update{{ $config->modelNames->name }}APIRequest $request): JsonResponse { - /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */ - ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id); - if (empty(${{ $config->modelNames->camel }})) { @if($config->options->localized) return $this->sendError( @@ -113,11 +107,8 @@ public function update($id, Update{{ $config->modelNames->name }}APIRequest $req } {!! $docDestroy !!} - public function destroy($id): JsonResponse + public function destroy({{ $config->modelNames->name }} ${{ $config->modelNames->camel }}): JsonResponse { - /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */ - ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id); - if (empty(${{ $config->modelNames->camel }})) { @if($config->options->localized) return $this->sendError( @@ -132,7 +123,7 @@ public function destroy($id): JsonResponse @if($config->options->localized) return $this->sendResponse( - $id, + ${{ $config->modelNames->camel }}->id, __('messages.deleted', ['model' => __('models/{{ $config->modelNames->camelPlural }}.singular')]) ); @else diff --git a/views/api/docs/controller/destroy.blade.php b/views/api/docs/controller/destroy.blade.php index 880335f7a..22b0808ca 100755 --- a/views/api/docs/controller/destroy.blade.php +++ b/views/api/docs/controller/destroy.blade.php @@ -1,6 +1,6 @@ /** * Remove the specified {{ $config->modelNames->name }} from storage. - * DELETE /{{ $config->modelNames->dashedPlural }}/{id} + * DELETE /{{ $config->modelNames->dashedPlural }}/{{ $config->modelNames->camel }} * * @throws \Exception */ \ No newline at end of file diff --git a/views/api/docs/controller/show.blade.php b/views/api/docs/controller/show.blade.php index 89ee701ce..35b05c3a4 100755 --- a/views/api/docs/controller/show.blade.php +++ b/views/api/docs/controller/show.blade.php @@ -1,4 +1,4 @@ /** * Display the specified {{ $config->modelNames->name }}. - * GET|HEAD /{{ $config->modelNames->dashedPlural }}/{id} + * GET|HEAD /{{ $config->modelNames->dashedPlural }}/{{ $config->modelNames->camel }} */ \ No newline at end of file diff --git a/views/api/docs/controller/update.blade.php b/views/api/docs/controller/update.blade.php index d3e413c9d..9435dfe3f 100755 --- a/views/api/docs/controller/update.blade.php +++ b/views/api/docs/controller/update.blade.php @@ -1,4 +1,4 @@ /** * Update the specified {{ $config->modelNames->name }} in storage. - * PUT/PATCH /{{ $config->modelNames->dashedPlural }}/{id} + * PUT/PATCH /{{ $config->modelNames->dashedPlural }}/{{ $config->modelNames->camel }} */ \ No newline at end of file diff --git a/views/scaffold/controller/controller.blade.php b/views/scaffold/controller/controller.blade.php index 1be8c5688..4eedab1ea 100644 --- a/views/scaffold/controller/controller.blade.php +++ b/views/scaffold/controller/controller.blade.php @@ -47,11 +47,8 @@ public function store(Create{{ $config->modelNames->name }}Request $request) /** * Display the specified {{ $config->modelNames->name }}. */ - public function show($id) + public function show({{ $config->modelNames->name }} ${{ $config->modelNames->camel }}) { - /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */ - ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id); - @include('laravel-generator::scaffold.controller.messages.not_found') return view('{{ $config->prefixes->getViewPrefixForInclude() }}{{ $config->modelNames->snakePlural }}.show')->with('{{ $config->modelNames->camel }}', ${{ $config->modelNames->camel }}); @@ -60,11 +57,8 @@ public function show($id) /** * Show the form for editing the specified {{ $config->modelNames->name }}. */ - public function edit($id) + public function edit({{ $config->modelNames->name }} ${{ $config->modelNames->camel }}) { - /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */ - ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id); - @include('laravel-generator::scaffold.controller.messages.not_found') return view('{{ $config->prefixes->getViewPrefixForInclude() }}{{ $config->modelNames->snakePlural }}.edit')->with('{{ $config->modelNames->camel }}', ${{ $config->modelNames->camel }}); @@ -73,11 +67,8 @@ public function edit($id) /** * Update the specified {{ $config->modelNames->name }} in storage. */ - public function update($id, Update{{ $config->modelNames->name }}Request $request) + public function update({{ $config->modelNames->name }} ${{ $config->modelNames->camel }}, Update{{ $config->modelNames->name }}Request $request) { - /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */ - ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id); - @include('laravel-generator::scaffold.controller.messages.not_found') ${{ $config->modelNames->camel }}->fill($request->all()); @@ -93,11 +84,8 @@ public function update($id, Update{{ $config->modelNames->name }}Request $reques * * @throws \Exception */ - public function destroy($id) + public function destroy({{ $config->modelNames->name }} ${{ $config->modelNames->camel }}) { - /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */ - ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id); - @include('laravel-generator::scaffold.controller.messages.not_found') ${{ $config->modelNames->camel }}->delete();