PHP code example of tharindu / service-maker

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

    

tharindu / service-maker example snippets

bash
php artisan make:service
bash


namespace App\Services\Product;

use App\Models\Product;

class ProductService
{
    protected $product;

    public function __construct(Product $product)
    {
        $this->product = $product;
    }

    // Example methods:
    public function store($data)
    {
        return $this->product->create($data);
    }

    public function update($data, $id)
    {
        return $this->product->where('id', $id)->update($data);
    }

    public function destroy($id)
    {
        return $this->product->destroy($id);
    }

    public function show($id)
    {
        return $this->product->find($id);
    }

    public function all()
    {
        return $this->product->all();
    }
}