PHP code example of baethon / laravel-resource

1. Go to this page and download the library: Download baethon/laravel-resource 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/ */

    

baethon / laravel-resource example snippets




namespace App\Http\Controllers;

use function Baethon\Laravel\Resource\resource;

class UserController
{
    public function show(\App\Models\User $user)
    {
        return resource($user);
    }
}



namespace App\Http\Resources;

use function Baethon\Laravel\Resource\resource;

class UserResource extends \Illuminate\Http\Resources\Json\JsonResource
{
    public function toArray($request)
    {
        return [
            'tags' => resource($this->whenLoaded('tags')),
        ];
    }
}

php artisan vendor:publish --provider="Baethon\Laravel\Resource\ServiceProvider"