Browse Source

[+] add queue

Artem Petrov 5 years ago
parent
commit
a9309d622f

+ 5 - 0
app/Http/Controllers/PostsController.php

@@ -9,8 +9,10 @@
 namespace App\Http\Controllers;
 
 use App\Http\Requests\PostRequest;
+use App\Jobs\SendMailJob;
 use App\Post;
 use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Mail;
 
 class PostsController extends Controller
 {
@@ -19,6 +21,9 @@ class PostsController extends Controller
      */
     public function index()
     {
+
+        SendMailJob::dispatch('the9thlaw@ukr.net');
+
         $posts = Post::all();
 
         return view('posts.index', [

+ 48 - 0
app/Jobs/SendMailJob.php

@@ -0,0 +1,48 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: artem
+ * Date: 17.10.18
+ * Time: 20:24
+ */
+
+namespace App\Jobs;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Support\Facades\Mail;
+
+class SendMailJob implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    protected $email;
+
+    /**
+     * Create a new job instance.
+     *
+     * @param  string  $email
+     * @return void
+     */
+    public function __construct($email)
+    {
+        $this->email = $email;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+
+        Mail::raw('Text to e-mail world', function($message)
+        {
+            $message->to($this->email);
+        });
+    }
+}

+ 1 - 0
composer.json

@@ -7,6 +7,7 @@
     "require": {
         "php": ">=7.0.0",
         "fideloper/proxy": "~3.3",
+        "guzzlehttp/guzzle": "^6.3",
         "laravel/framework": "5.5.*",
         "laravel/tinker": "~1.0",
         "santigarcor/laratrust": "5.0.*"

+ 232 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "content-hash": "87c514deb5f77c2a6afc16c500837711",
+    "content-hash": "40ad61f3a06eec316a16cc7ecd04b21c",
     "packages": [
         {
             "name": "dnoegel/php-xdg-base-dir",
@@ -320,6 +320,187 @@
             ],
             "time": "2017-06-15T17:19:42+00:00"
         },
+        {
+            "name": "guzzlehttp/guzzle",
+            "version": "6.3.3",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/guzzle/guzzle.git",
+                "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba",
+                "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba",
+                "shasum": ""
+            },
+            "require": {
+                "guzzlehttp/promises": "^1.0",
+                "guzzlehttp/psr7": "^1.4",
+                "php": ">=5.5"
+            },
+            "require-dev": {
+                "ext-curl": "*",
+                "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0",
+                "psr/log": "^1.0"
+            },
+            "suggest": {
+                "psr/log": "Required for using the Log middleware"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "6.3-dev"
+                }
+            },
+            "autoload": {
+                "files": [
+                    "src/functions_include.php"
+                ],
+                "psr-4": {
+                    "GuzzleHttp\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Michael Dowling",
+                    "email": "mtdowling@gmail.com",
+                    "homepage": "https://github.com/mtdowling"
+                }
+            ],
+            "description": "Guzzle is a PHP HTTP client library",
+            "homepage": "http://guzzlephp.org/",
+            "keywords": [
+                "client",
+                "curl",
+                "framework",
+                "http",
+                "http client",
+                "rest",
+                "web service"
+            ],
+            "time": "2018-04-22T15:46:56+00:00"
+        },
+        {
+            "name": "guzzlehttp/promises",
+            "version": "v1.3.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/guzzle/promises.git",
+                "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
+                "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.5.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.4-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "GuzzleHttp\\Promise\\": "src/"
+                },
+                "files": [
+                    "src/functions_include.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Michael Dowling",
+                    "email": "mtdowling@gmail.com",
+                    "homepage": "https://github.com/mtdowling"
+                }
+            ],
+            "description": "Guzzle promises library",
+            "keywords": [
+                "promise"
+            ],
+            "time": "2016-12-20T10:07:11+00:00"
+        },
+        {
+            "name": "guzzlehttp/psr7",
+            "version": "1.4.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/guzzle/psr7.git",
+                "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
+                "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.4.0",
+                "psr/http-message": "~1.0"
+            },
+            "provide": {
+                "psr/http-message-implementation": "1.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "~4.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.4-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "GuzzleHttp\\Psr7\\": "src/"
+                },
+                "files": [
+                    "src/functions_include.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Michael Dowling",
+                    "email": "mtdowling@gmail.com",
+                    "homepage": "https://github.com/mtdowling"
+                },
+                {
+                    "name": "Tobias Schultze",
+                    "homepage": "https://github.com/Tobion"
+                }
+            ],
+            "description": "PSR-7 message implementation that also provides common utility methods",
+            "keywords": [
+                "http",
+                "message",
+                "request",
+                "response",
+                "stream",
+                "uri",
+                "url"
+            ],
+            "time": "2017-03-20T17:10:46+00:00"
+        },
         {
             "name": "jakub-onderka/php-console-color",
             "version": "0.1",
@@ -1055,6 +1236,56 @@
             ],
             "time": "2017-02-14T16:28:37+00:00"
         },
+        {
+            "name": "psr/http-message",
+            "version": "1.0.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/php-fig/http-message.git",
+                "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
+                "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.3.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Psr\\Http\\Message\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "PHP-FIG",
+                    "homepage": "http://www.php-fig.org/"
+                }
+            ],
+            "description": "Common interface for HTTP messages",
+            "homepage": "https://github.com/php-fig/http-message",
+            "keywords": [
+                "http",
+                "http-message",
+                "psr",
+                "psr-7",
+                "request",
+                "response"
+            ],
+            "time": "2016-08-06T14:39:51+00:00"
+        },
         {
             "name": "psr/log",
             "version": "1.0.2",

BIN
composer.phar


+ 210 - 0
config/laratrust.php

@@ -0,0 +1,210 @@
+<?php
+
+/**
+ * This file is part of Laratrust,
+ * a role & permission management solution for Laravel.
+ *
+ * @license MIT
+ * @package Laratrust
+ */
+
+return [
+    /*
+    |--------------------------------------------------------------------------
+    | Use MorphMap in relationships between models
+    |--------------------------------------------------------------------------
+    |
+    | If true, the morphMap feature is going to be used. The array values that
+    | are going to be used are the ones inside the 'user_models' array.
+    |
+    */
+    'use_morph_map' => false,
+
+    /*
+    |--------------------------------------------------------------------------
+    | Use cache in the package
+    |--------------------------------------------------------------------------
+    |
+    | Defines if Laratrust will use Laravel's Cache to cache the roles and permissions.
+    |
+    */
+    'use_cache' => true,
+
+    /*
+    |--------------------------------------------------------------------------
+    | Use teams feature in the package
+    |--------------------------------------------------------------------------
+    |
+    | Defines if Laratrust will use the teams feature.
+    | Please check the docs to see what you need to do in case you have the package already configured.
+    |
+    */
+    'use_teams' => false,
+
+    /*
+    |--------------------------------------------------------------------------
+    | Strict check for roles/permissions inside teams
+    |--------------------------------------------------------------------------
+    |
+    | Determines if a strict check should be done when checking if a role or permission
+    | is attached inside a team.
+    | If it's false, when checking a role/permission without specifying the team,
+    | it will check only if the user has attached that role/permission ignoring the team.
+    |
+    */
+    'teams_strict_check' => false,
+
+    /*
+    |--------------------------------------------------------------------------
+    | Laratrust User Models
+    |--------------------------------------------------------------------------
+    |
+    | This is the array that contains the information of the user models.
+    | This information is used in the add-trait command, and for the roles and
+    | permissions relationships with the possible user models.
+    |
+    | The key in the array is the name of the relationship inside the roles and permissions.
+    |
+    */
+    'user_models' => [
+        'users' => 'App\User',
+    ],
+
+    /*
+    |--------------------------------------------------------------------------
+    | Laratrust Models
+    |--------------------------------------------------------------------------
+    |
+    | These are the models used by Laratrust to define the roles, permissions and teams.
+    | If you want the Laratrust models to be in a different namespace or
+    | to have a different name, you can do it here.
+    |
+    */
+    'models' => [
+        /**
+         * Role model
+         */
+        'role' => 'App\Role',
+
+        /**
+         * Permission model
+         */
+        'permission' => 'App\Permission',
+
+        /**
+         * Team model
+         */
+        'team' => 'App\Team',
+
+    ],
+
+    /*
+    |--------------------------------------------------------------------------
+    | Laratrust Tables
+    |--------------------------------------------------------------------------
+    |
+    | These are the tables used by Laratrust to store all the authorization data.
+    |
+    */
+    'tables' => [
+        /**
+         * Roles table.
+         */
+        'roles' => 'roles',
+
+        /**
+         * Permissions table.
+         */
+        'permissions' => 'permissions',
+
+        /**
+         * Teams table.
+         */
+        'teams' => 'teams',
+
+        /**
+         * Role - User intermediate table.
+         */
+        'role_user' => 'role_user',
+
+        /**
+         * Permission - User intermediate table.
+         */
+        'permission_user' => 'permission_user',
+
+        /**
+         * Permission - Role intermediate table.
+         */
+        'permission_role' => 'permission_role',
+
+    ],
+
+    /*
+    |--------------------------------------------------------------------------
+    | Laratrust Foreign Keys
+    |--------------------------------------------------------------------------
+    |
+    | These are the foreign keys used by laratrust in the intermediate tables.
+    |
+    */
+    'foreign_keys' => [
+        /**
+         * User foreign key on Laratrust's role_user and permission_user tables.
+         */
+        'user' => 'user_id',
+
+        /**
+         * Role foreign key on Laratrust's role_user and permission_role tables.
+         */
+        'role' => 'role_id',
+
+        /**
+         * Role foreign key on Laratrust's permission_user and permission_role tables.
+         */
+        'permission' => 'permission_id',
+
+        /**
+         * Role foreign key on Laratrust's role_user and permission_user tables.
+         */
+        'team' => 'team_id',
+
+    ],
+
+    /*
+    |--------------------------------------------------------------------------
+    | Laratrust Middleware
+    |--------------------------------------------------------------------------
+    |
+    | This configuration helps to customize the Laratrust middleware behavior.
+    |
+    */
+    'middleware' => [
+        /**
+         * Define if the laratrust middleware are registered automatically in the service provider
+         */
+        'register' => true,
+
+        /**
+         * Method to be called in the middleware return case.
+         * Available: abort|redirect
+         */
+        'handling' => 'abort',
+
+        /**
+         * Parameter passed to the middleware_handling method
+         */
+        'params' => '403',
+
+    ],
+
+    /*
+    |--------------------------------------------------------------------------
+    | Laratrust Magic 'can' Method
+    |--------------------------------------------------------------------------
+    |
+    | Supported cases for the magic can method (Refer to the docs).
+    | Available: camel_case|snake_case|kebab_case
+    |
+    */
+    'magic_can_method_case' => 'kebab_case',
+];

+ 29 - 0
config/laratrust_seeder.php

@@ -0,0 +1,29 @@
+<?php
+
+return [
+    'role_structure' => [
+        'superadministrator' => [
+            'users' => 'c,r,u,d',
+            'acl' => 'c,r,u,d',
+            'profile' => 'r,u'
+        ],
+        'administrator' => [
+            'users' => 'c,r,u,d',
+            'profile' => 'r,u'
+        ],
+        'user' => [
+            'profile' => 'r,u'
+        ],
+    ],
+    'permission_structure' => [
+        'cru_user' => [
+            'profile' => 'c,r,u'
+        ],
+    ],
+    'permissions_map' => [
+        'c' => 'create',
+        'r' => 'read',
+        'u' => 'update',
+        'd' => 'delete'
+    ]
+];

+ 36 - 0
database/migrations/2018_10_17_172010_create_jobs_table.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateJobsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('jobs', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->string('queue')->index();
+            $table->longText('payload');
+            $table->unsignedTinyInteger('attempts');
+            $table->unsignedInteger('reserved_at')->nullable();
+            $table->unsignedInteger('available_at');
+            $table->unsignedInteger('created_at');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('jobs');
+    }
+}