Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement route-model binding by default #1059

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 4 additions & 13 deletions views/api/controller/model/controller.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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
Expand Down
17 changes: 4 additions & 13 deletions views/api/controller/model/controller_resource.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion views/api/docs/controller/destroy.blade.php
Original file line number Diff line number Diff line change
@@ -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
*/
2 changes: 1 addition & 1 deletion views/api/docs/controller/show.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Display the specified {{ $config->modelNames->name }}.
* GET|HEAD /{{ $config->modelNames->dashedPlural }}/{id}
* GET|HEAD /{{ $config->modelNames->dashedPlural }}/{{ $config->modelNames->camel }}
*/
2 changes: 1 addition & 1 deletion views/api/docs/controller/update.blade.php
Original file line number Diff line number Diff line change
@@ -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 }}
*/
20 changes: 4 additions & 16 deletions views/scaffold/controller/controller.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 }});
Expand All @@ -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 }});
Expand All @@ -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());
Expand 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();
Expand Down