PHP code example of spinen / laravel-formio
1. Go to this page and download the library: Download spinen/laravel-formio 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/ */
spinen / laravel-formio example snippets
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spinen\Formio\Concerns\HasForms;
use Spinen\Formio\Contracts\FormioUser;
class User extends Authenticatable implements FormioUser
{
use FormioUser, Notifiable;
// ...
}
$ php artisan tinker
Psy Shell v0.9.9 (PHP 7.2.14 — cli) by Justin Hileman
>>> $formio = app(Spinen\Formio\Client::class)
=> Spinen\Formio\Client {#3534
+token: Spinen\Formio\Token {#3528
// ...
},
}
>>> $formio->login()
=> Spinen\Formio\Client {#3534
+token: Spinen\Formio\Token {#3528
// ...
+user: [
"_id" => "5d916b270ea0c7001a8eee4a",
"owner" => null,
"roles" => [
"5d916b260ea0c7001a8eee39",
],
"form" => "5d916b260ea0c7001a8eee3d",
"data" => [
"email" => "[email protected] ",
],
// ...
],
},
}
>>> $formio->request('/role')
=> [
[
"_id" => "5d916b260ea0c7001a8eee39",
"description" => "A role for Administrative Users.",
"default" => false,
"admin" => true,
"title" => "Administrator",
"machineName" => "administrator",
"created" => "2019-09-30T02:40:38.377Z",
"modified" => "2019-09-30T02:40:38.491Z",
],
[
"_id" => "5d916b260ea0c7001a8eee3b",
"description" => "A role for Anonymous Users.",
"default" => true,
"admin" => false,
"title" => "Anonymous",
"machineName" => "anonymous",
"created" => "2019-09-30T02:40:38.735Z",
"modified" => "2019-09-30T02:40:38.737Z",
],
[
"_id" => "5d916b260ea0c7001a8eee3a",
"description" => "A role for Authenticated Users.",
"default" => false,
"admin" => false,
"title" => "Authenticated",
"machineName" => "authenticated",
"created" => "2019-09-30T02:40:38.648Z",
"modified" => "2019-09-30T02:40:38.682Z",
],
]
>>>
$ php artisan tinker
>>> $user = factory(App\User::class)->create()
=> App\User {#3565
first_name: "Arvid",
last_name: "Ruecker",
email: "[email protected] ",
email_verified_at: "2019-10-03 21:38:33",
updated_at: "2019-10-03 21:38:33",
created_at: "2019-10-03 21:38:33",
id: 1,
}
>>> $formio = app(Spinen\Formio\Client::class)
=> Spinen\Formio\Client {#3697
+token: Spinen\Formio\Token {#3530
// ...
},
}
>>> $formio->sso($user)
=> Spinen\Formio\Client {#3697
+token: Spinen\Formio\Token {#3530
+expires_at: Carbon\Carbon @1570153122 {#3695
date: 2019-10-04 01:38:42.0 +00:00,
},
+issued_at: Carbon\Carbon @1570138722 {#3619
date: 2019-10-03 21:38:42.0 +00:00,
},
+jwt: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHRlcm5hbCI6dHJ1ZSwiZm9ybSI6eyJfaWQiOiI1ZDkxNmIyNjBlYTBjNzAwMWE4ZWVlM2MifSwidXNlciI6eyJfaWQiOiJleHRlcm5hbCIsImRhdGEiOnsiZW1haWwiOiJvamFjb2JzQGV4YW1wbGUub3JnIiwiZmlyc3ROYW1lIjoiQXJ2aWQiLCJsYXN0TmFtZSI6IlJ1ZWNrZXIifSwicm9sZXMiOlsiNWQ5MTZiMjYwZWEwYzcwMDFhOGVlZTNhIl19LCJpYXQiOjE1NzAxMzg3MjIsImV4cCI6MTU3MDE1MzEyMn0.ZxWTJIteHXomGz1F7yYjSJcXvWLZQZYRrPN4cKB3KAk",
+jwt_obj: {#3575
+"external": true,
+"form": {#3535
+"_id": "5d916b260ea0c7001a8eee3c",
},
+"user": {#3676
+"_id": "external",
+"data": {#3527
+"email": "[email protected] ",
+"firstName": "Arvid",
+"lastName": "Ruecker",
},
+"roles": [
"5d916b260ea0c7001a8eee3a",
],
},
+"iat": 1570138722,
+"exp": 1570153122,
},
+user: [
"email" => "[email protected] ",
"firstName" => "Arvid",
"lastName" => "Ruecker",
],
},
}
>>> collect($formio->request('/form'))->pluck('name')
=> Illuminate\Support\Collection {#3536
all: [
"user",
"admin",
"userLogin",
"adminLogin",
"userRegister",
],
}
>>>
$ psysh
Psy Shell v0.9.9 (PHP 7.2.22 — cli) by Justin Hileman
>>> $config = [
"admin" => [
"password" => "password",
"login" => [
"path" => "/admin/login",
],
"username" => "[email protected] ",
],
"jwt" => [
"algorithm" => "HS256",
"secret" => "--- change me now ---",
],
"project" => [
"id" => null,
],
"url" => "http://localhost:3001",
"user" => [
"form" => null,
"login" => [
"path" => "/user/login",
],
"register" => [
"default_password" => null,
"path" => "/user/register",
],
"roles" => [],
"sync" => false,
],
]
>>> $guzzle = new GuzzleHttp\Client();
=> GuzzleHttp\Client {#2346}
>>> $formio = new Spinen\Formio\Client($config, $guzzle);
=> Spinen\Formio\Client {#2364
+token: Spinen\Formio\Token {#2362
// ...
},
}
>>> $formio->login();
=> Spinen\Formio\Client {#2364
+token: Spinen\Formio\Token {#2362
// ...
+user: [
"_id" => "5d916b270ea0c7001a8eee4a",
"owner" => null,
"roles" => [
"5d916b260ea0c7001a8eee39",
],
"form" => "5d916b260ea0c7001a8eee3d",
"data" => [
"email" => "[email protected] ",
],
"access" => [],
"externalIds" => [],
"created" => "2019-09-30T02:40:39.478Z",
"modified" => "2019-09-30T02:40:39.482Z",
],
},
}
>>> $formio->request('/current')
=> [
"_id" => "5d916b270ea0c7001a8eee4a",
"owner" => null,
"roles" => [
"5d916b260ea0c7001a8eee39",
],
"form" => "5d916b260ea0c7001a8eee3d",
"data" => [
"email" => "[email protected] ",
],
"access" => [],
"externalIds" => [],
"created" => "2019-09-30T02:40:39.478Z",
"modified" => "2019-09-30T02:40:39.482Z",
]
>>>
formio.php
bash
php artisan vendor:publish --tag=formio-config
bash
php artisan vendor:publish --tag=formio-migrations