PHP code example of pixelcone / fraction

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

    

pixelcone / fraction example snippets




namespace App\Actions;

use App\Models\User;
use Pixelcone\Fraction\AsAction;

class CreateUserAction {
    use AsAction;

    public function __construct(
        protected string $fullName;
        protected string $email;
        protected string $password;
    )
    {}
    
    public function handle ()
    {
        // User storing logic here.
        // This method can return anything
        // or can return nothing.
        
        [$firstName, $lastName] = $this->getFullNameParts();
        
        $user = new User();
        
        $user->create([
            'first_name' => $firstName,
            'last_name'  => $lastName,
            'email'      => $this->email,
            'password'   => bcrypt($this->password);
        ]);
    }
    
    protected function getFullNameParts (): array
    {
        // this method does some internal job
        // and is accessible within
        // this particular Action only
        
        return explode(' ', $this->fullName);
    }
}

CreateUserAction::run('Alex Doe', '[email protected]', 'pass');



namespace App\Http\Features;

use App\Models\User;

class ShowProfilePageFeature {    
    public function handle ($request)
    {
        // Feature logic here.
        // This method may return any kind of
        // response if the outer code        // Some complex logic here.
        // This method does some internal job
        // and is accessible within
        // this particular Feature only.
        
        return $user->messages();
    }
}



namespace App\Http\Controllers;

use App\Http\Features\ShowProfilePageFeature;
use Pixelcone\Fraction\RunsFeatures;

class ProfileController {
    use RunsFeatures;

    // ...
    
    public function index ()
    {
        return $this->run(ShowProfilePageFeature::class);
    }
    
    // ...
}