1. Go to this page and download the library: Download larapie/actions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$action = new Action(['key' => 'value']); // Initialise an action with the provided attribute.
$action->fill(['key' => 'value']); // Merge the new attributes with the existing attributes.
$action->all(); // Retrieve all attributes of an action as an array.
$action->only('title', 'body'); // Retrieve only the attributes provided.
$action->except('body'); // Retrieve all attributes excepts the one provided.
$action->has('title'); // Whether the action has the provided attribute.
$action->get('title'); // Get an attribute.
$action->get('title', 'Untitled'); // Get an attribute with default value.
$action->set('title', 'My blog post'); // Set an attribute.
$action->title; // Get an attribute.
$action->title = 'My blog post'; // Set an attribute.
// Resolved from the IoC container.publicfunctionhandle(Request $request){/* ... */}
publicfunctionhandle(MyService $service){/* ... */}
// Resolved from the attributes.// -- $title and $body are equivalent to $action->title and $action->body// -- When attributes are missing, null will be returned unless a default value is provided.publicfunctionhandle($title, $body){/* ... */}
publicfunctionhandle($title, $body = 'default'){/* ... */}
// Resolved from the attributes using route model binding.// -- If $action->comment is already an instance of Comment, it provides it.// -- If $action->comment is an id, it will provide the right instance of Comment from the database or fail.// -- This will also update $action->comment to be that instance.publicfunctionhandle(Comment $comment){/* ... */}
// They can all be combined.publicfunctionhandle($title, Comment $comment, MyService $service){/* ... */}
publicfunctionauthorize(){
// Your authorisation logic here...
}
publicfunctionwithValidator($validator){
$validator->after(function($validator){
if ($this->somethingElseIsInvalid()) {
$validator->errors()->add('field', 'Something is wrong with this field!');
}
});
}
publicfunctionafterValidator($validator){
if ($this->somethingElseIsInvalid()) {
$validator->errors()->add('field', 'Something is wrong with this field!');
};
}
publicfunctionhandle(){
$this->runningAs('object');
$this->runningAs('job');
$this->runningAs('listener');
$this->runningAs('controller');
// Returns true of any of them is true.$this->runningAs('object', 'job');
}