PHP code example of zachflower / eloquent-interactions
1. Go to this page and download the library: Download zachflower/eloquent-interactions 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/ */
zachflower / eloquent-interactions example snippets
namespace App\Interactions;
use ZachFlower\EloquentInteractions\Interaction;
class ConvertMetersToMiles extends Interaction
{
/**
* Parameter validations
*
* @var array
*/
public $validations = [
//
];
/**
* Execute the interaction
*
* @return void
*/
public function execute() {
//
}
}
namespace App\Interactions;
use ZachFlower\EloquentInteractions\Interaction;
class ConvertMetersToMiles extends Interaction
{
/**
* Parameter validations
*
* @var array
*/
public $validations = [
'meters' => '
>>> $outcome = ConvertMetersToMiles::run(['meters' => 100]);
>>> $outcome->valid;
=> true
>>> $outcome->result;
=> 0.0621371
>>> $outcome = ConvertMetersToMiles::run(['meters' => 'one hundred']);
>>> $outcome->valid;
=> false
>>> $outcome->errors->toArray()
=> [
"meters" => [
"The meters field must be a number.",
],
]
>>> $outcome = App\Interactions\Utility\ConvertMetersToMiles::run(['meters' => 'one hundred'], TRUE);
Illuminate\Validation\ValidationException with message 'The given data failed to pass validation.'
>>> $outcome->errors->toArray();
=> [
"meters" => [
"The meters field must be a number.",
],
]
namespace App\Interactions;
use ZachFlower\EloquentInteractions\Interaction;
class ConvertMetersToMiles extends Interaction
{
/**
* Execute the interaction
*
* @return void
*/
public function execute() {
return $this->meters * 0.000621371;
}
/**
* Parameter validations
*
* @var array
*/
public function validations()
{
return [
'meters' => ['
public $validations = [
'user' => '
public function execute() {
$this->validator->errors()->add('entity', 'The entity object type is invalid.');
}
php artisan make:interaction ConvertMetersToMiles
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.