1. Go to this page and download the library: Download koala-labs/pouch 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/ */
koala-labs / pouch example snippets
/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router)
{
// Register a handy macro for registering resource routes
$router->macro('restful', function ($model_name, $resource_controller = 'ResourceController') use ($router) {
$alias = Str::lower(Str::snake(Str::plural(class_basename($model_name)), '-'));
$router->resource($alias, $resource_controller, [
'only' => [
'index',
'store',
'show',
'update',
'destroy',
],
]);
});
$router->group(['namespace' => $this->namespace], function ($router) {
$repository = (new EloquentRepository)
->setModelClass('User')
->setInput([
'username' => 'steve',
'posts' => [
'title' => 'Stuff',
],
'reactions' => [
[
'id': 1 //The Reaction model must already exist, and relate to a Post
]
]
]);
$user = $repository->save();
$repository = (new EloquentRepository)
->setModelClass('User')
->setInput([
'username' => 'steve',
//The Post is related to the User, and the Reaction is related to the Post. User Reactions are related through the Post.
'posts' => [
'title' => 'Stuff',
'reactions' => [
[
'name' => 'John Doe',
'icon' => 'thumbs-up'
]
]
],
]);
$user = $repository->save();