PHP code example of khant-nyar / service-extender

1. Go to this page and download the library: Download khant-nyar/service-extender 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/ */

    

khant-nyar / service-extender example snippets


/** 
 * Example uses with UserService 
 */

namespace App\Services;

use App\Models\User;
use KhantNyar\ServiceExtender\Services\EloquenceService;

class UserService extends EloquenceService
{
    protected static string $model = User::class;
}

/**
 * Example uses in controller
 */

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Services\UserService;

class UserController extends Controller
{
    public function index()
    {
        return response()->json(UserService::all());
    }

    public function show($id)
    {
        return response()->json(UserService::find((int) $id));
    }

    public function store(Request $request)
    {
        $data = $request->validate([
            'name' => 'UserService::update((int) $id, $data));
    }

    public function destroy($id)
    {
        return response()->json(['success' => UserService::delete((int) $id)]);
    }
}