PHP code example of softonic / rest-api-nested-resources

1. Go to this page and download the library: Download softonic/rest-api-nested-resources library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

softonic / rest-api-nested-resources example snippets


class UserCommentModel extends MultiKeyModel
{
    /**
     * Identifiers to be hashed and used in the real primary and foreign keys.
     */
    protected static array $generatedIds = [
        'id_user_comment' => [
            'id_user',
            'id_comment',
        ],
    ];
}

class UserCommentController extends Controller
{
    protected function setMiddlewares(Request $request)
    {
        $this->middleware(
            'App\Http\Middleware\EnsureModelExists:App\Models\User,id_user',
            ['only' => ['store', 'update']]
        );

        $this->middleware(
            'App\Http\Middleware\EnsureModelDoesNotExist:App\Models\UserComment,id_user,id_comment',
            ['only' => 'store']
        );
    }
}

use App\Models\UserComment;

class UserCommentController extends Controller
{
    public function show(UserComment $userComment)
    {
        ...
    }
}

use App\Models\UserComment;

class UserCommentController extends Controller
{
    use SplitPutPatchVerbs;

    public function modify(UserComment $userComment, Request $request)
    {
        ...
    }

    public function replace(Request $request, string $id_user, string $id_comment)
    {
        ...
    }
}