-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option to disable generation of separate resource collection class (#723
- Loading branch information
Showing
9 changed files
with
226 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/fixtures/controllers/without-generating-resource-collection-classes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Requests\PostStoreRequest; | ||
use App\Http\Requests\PostUpdateRequest; | ||
use App\Http\Resources\PostResource; | ||
use App\Models\Post; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\ResourceCollection; | ||
use Illuminate\Http\Response; | ||
|
||
class PostController extends Controller | ||
{ | ||
public function index(Request $request): ResourceCollection | ||
{ | ||
$posts = Post::paginate(); | ||
|
||
return PostResource::collection($posts); | ||
} | ||
|
||
public function store(PostStoreRequest $request): PostResource | ||
{ | ||
$post = Post::create($request->validated()); | ||
|
||
return new PostResource($post); | ||
} | ||
|
||
public function show(Request $request, Post $post): PostResource | ||
{ | ||
return new PostResource($post); | ||
} | ||
|
||
public function update(PostUpdateRequest $request, Post $post): PostResource | ||
{ | ||
$post->update($request->validated()); | ||
|
||
return new PostResource($post); | ||
} | ||
|
||
public function destroy(Request $request, Post $post): Response | ||
{ | ||
$post->delete(); | ||
|
||
return response()->noContent(); | ||
} | ||
} |