├── public ├── favicon.ico ├── robots.txt ├── .htaccess ├── web.config └── index.php ├── tests ├── Unit │ └── .gitkeep ├── TestCase.php ├── CreatesApplication.php └── Feature │ ├── TestCase.php │ ├── CommentsTest.php │ ├── SitesTest.php │ └── PostsTest.php ├── app ├── Listeners │ └── .gitkeep ├── Events │ ├── Event.php │ └── PostCreated.php ├── Http │ ├── Requests │ │ └── Request.php │ ├── Middleware │ │ ├── EncryptCookies.php │ │ ├── VerifyCsrfToken.php │ │ ├── TrimStrings.php │ │ ├── TrustProxies.php │ │ └── RedirectIfAuthenticated.php │ ├── Controllers │ │ ├── Controller.php │ │ ├── Api │ │ │ └── PostsController.php │ │ ├── HomeController.php │ │ └── Auth │ │ │ ├── ForgotPasswordController.php │ │ │ ├── LoginController.php │ │ │ ├── ResetPasswordController.php │ │ │ └── RegisterController.php │ └── Kernel.php ├── Tag.php ├── Comment.php ├── Providers │ ├── EventServiceProvider.php │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ └── RouteServiceProvider.php ├── JsonApi │ ├── Tags │ │ ├── Adapter.php │ │ └── Schema.php │ ├── Users │ │ ├── Validators.php │ │ ├── Schema.php │ │ └── Adapter.php │ ├── Sites │ │ ├── Schema.php │ │ ├── Validators.php │ │ ├── Authorizer.php │ │ └── Adapter.php │ ├── Comments │ │ ├── Adapter.php │ │ └── Schema.php │ ├── Posts │ │ ├── Validators.php │ │ ├── Adapter.php │ │ └── Schema.php │ └── DefaultAuthorizer.php ├── Jobs │ └── Job.php ├── User.php ├── Console │ ├── Commands │ │ └── Inspire.php │ └── Kernel.php ├── Post.php ├── Policies │ ├── UserPolicy.php │ ├── PostPolicy.php │ └── CommentPolicy.php ├── Exceptions │ └── Handler.php ├── SiteRepository.php └── Site.php ├── database ├── .gitignore ├── seeds │ ├── DatabaseSeeder.php │ └── PostSeeder.php ├── migrations │ ├── 2014_10_12_100000_create_password_resets_table.php │ ├── 2018_02_28_141331_add_posts_column_published_at.php │ ├── 2014_10_12_000000_create_users_table.php │ ├── 2016_09_03_153707_create-tags-table.php │ └── 2016_06_04_063426_create-posts-and-comments-tables.php └── factories │ └── ModelFactory.php ├── resources ├── views │ ├── vendor │ │ └── .gitkeep │ ├── home.blade.php │ ├── errors │ │ └── 503.blade.php │ ├── auth │ │ ├── passwords │ │ │ ├── email.blade.php │ │ │ └── reset.blade.php │ │ ├── login.blade.php │ │ └── register.blade.php │ └── layouts │ │ └── app.blade.php ├── assets │ ├── sass │ │ ├── _variables.scss │ │ └── app.scss │ └── js │ │ ├── app.js │ │ ├── bootstrap.js │ │ └── components │ │ └── passport │ │ ├── AuthorizedClients.vue │ │ ├── PersonalAccessTokens.vue │ │ └── Clients.vue └── lang │ └── en │ ├── pagination.php │ ├── auth.php │ ├── passwords.php │ └── validation.php ├── bootstrap ├── cache │ └── .gitignore └── app.php ├── storage ├── logs │ └── .gitignore ├── app │ ├── public │ │ └── .gitignore │ └── .gitignore └── framework │ ├── cache │ └── .gitignore │ ├── views │ └── .gitignore │ ├── sessions │ └── .gitignore │ └── .gitignore ├── .gitattributes ├── after.sh ├── .editorconfig ├── .gitignore ├── .env.example ├── config ├── hashing.php ├── compile.php ├── services.php ├── view.php ├── broadcasting.php ├── logging.php ├── filesystems.php ├── cache.php ├── queue.php ├── auth.php ├── mail.php ├── database.php ├── json-api-v1.php ├── session.php └── app.php ├── webpack.mix.js ├── routes ├── console.php ├── web.php └── api.php ├── server.php ├── package.json ├── phpunit.xml ├── artisan ├── composer.json └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/Unit/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/Listeners/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /resources/views/vendor/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !public/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.scss linguist-vendored 4 | -------------------------------------------------------------------------------- /app/Events/Event.php: -------------------------------------------------------------------------------- 1 | 5 |
6 |
7 | 8 |
9 |
10 | 11 | @endsection 12 | -------------------------------------------------------------------------------- /resources/assets/sass/app.scss: -------------------------------------------------------------------------------- 1 | 2 | // Fonts 3 | @import url("https://fonts.googleapis.com/css?family=Raleway:300,400,600"); 4 | 5 | // Variables 6 | @import "variables"; 7 | 8 | // Bootstrap 9 | @import '~bootstrap/scss/bootstrap'; 10 | 11 | .navbar-laravel { 12 | background-color: #fff; 13 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04); 14 | } 15 | -------------------------------------------------------------------------------- /app/Http/Middleware/EncryptCookies.php: -------------------------------------------------------------------------------- 1 | belongsToMany(Post::class); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 19 | 20 | return $app; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/Comment.php: -------------------------------------------------------------------------------- 1 | belongsTo(Post::class); 17 | } 18 | 19 | /** 20 | * @return BelongsTo 21 | */ 22 | public function user() 23 | { 24 | return $this->belongsTo(User::class); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_ENV=local 2 | APP_DEBUG=true 3 | APP_KEY=SomeRandomString 4 | APP_URL=http://localhost 5 | 6 | DB_CONNECTION=mysql 7 | DB_HOST=127.0.0.1 8 | DB_PORT=3306 9 | DB_DATABASE=homestead 10 | DB_USERNAME=homestead 11 | DB_PASSWORD=secret 12 | 13 | CACHE_DRIVER=file 14 | SESSION_DRIVER=file 15 | QUEUE_DRIVER=sync 16 | 17 | REDIS_HOST=127.0.0.1 18 | REDIS_PASSWORD=null 19 | REDIS_PORT=6379 20 | 21 | MAIL_DRIVER=smtp 22 | MAIL_HOST=mailtrap.io 23 | MAIL_PORT=2525 24 | MAIL_USERNAME=null 25 | MAIL_PASSWORD=null 26 | MAIL_ENCRYPTION=null 27 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrustProxies.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'App\Listeners\EventListener', 18 | ], 19 | ]; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /tests/Feature/TestCase.php: -------------------------------------------------------------------------------- 1 | 'Frankie Manning', 16 | 'email' => 'frankie@example.com', 17 | 'password' => bcrypt('password'), 18 | ]); 19 | 20 | factory(\App\Tag::class, 10)->create(); 21 | 22 | $this->call(PostSeeder::class); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/Http/Controllers/HomeController.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 17 | } 18 | 19 | /** 20 | * Show the application dashboard. 21 | * 22 | * @return \Illuminate\Http\Response 23 | */ 24 | public function index() 25 | { 26 | return view('home'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/JsonApi/Tags/Adapter.php: -------------------------------------------------------------------------------- 1 | 'bcrypt', 19 | 20 | ]; 21 | -------------------------------------------------------------------------------- /webpack.mix.js: -------------------------------------------------------------------------------- 1 | let mix = require('laravel-mix'); 2 | 3 | /* 4 | |-------------------------------------------------------------------------- 5 | | Mix Asset Management 6 | |-------------------------------------------------------------------------- 7 | | 8 | | Mix provides a clean, fluent API for defining some Webpack build steps 9 | | for your Laravel application. By default, we are compiling the Sass 10 | | file for the application as well as bundling up all the JS files. 11 | | 12 | */ 13 | 14 | mix.js('resources/assets/js/app.js', 'public/js') 15 | .sass('resources/assets/sass/app.scss', 'public/css'); 16 | -------------------------------------------------------------------------------- /app/Jobs/Job.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 18 | })->describe('Display an inspiring quote'); 19 | -------------------------------------------------------------------------------- /resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /app/User.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | name('home'); 22 | -------------------------------------------------------------------------------- /app/Http/Middleware/RedirectIfAuthenticated.php: -------------------------------------------------------------------------------- 1 | check()) { 21 | return redirect('/home'); 22 | } 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Redirect Trailing Slashes If Not A Folder... 9 | RewriteCond %{REQUEST_FILENAME} !-d 10 | RewriteCond %{REQUEST_URI} (.+)/$ 11 | RewriteRule ^ %1 [L,R=301] 12 | 13 | # Handle Front Controller... 14 | RewriteCond %{REQUEST_FILENAME} !-d 15 | RewriteCond %{REQUEST_FILENAME} !-f 16 | RewriteRule ^ index.php [L] 17 | 18 | # Handle Authorization Header 19 | RewriteCond %{HTTP:Authorization} . 20 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 21 | 22 | -------------------------------------------------------------------------------- /resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /app/JsonApi/Users/Validators.php: -------------------------------------------------------------------------------- 1 | comment(PHP_EOL.Inspiring::quote().PHP_EOL); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/JsonApi/Sites/Schema.php: -------------------------------------------------------------------------------- 1 | getSlug(); 23 | } 24 | 25 | /** 26 | * @param Site $resource 27 | * @return array 28 | */ 29 | public function getAttributes($resource) 30 | { 31 | return [ 32 | 'domain' => $resource->getDomain(), 33 | 'name' => $resource->getName(), 34 | ]; 35 | } 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /app/JsonApi/Sites/Validators.php: -------------------------------------------------------------------------------- 1 | 'required|string', 24 | 'domain' => "required|url", 25 | 'name' => "required|string|min:1", 26 | ]; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | protected function queryRules(): array 33 | { 34 | return []; 35 | } 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_100000_create_password_resets_table.php: -------------------------------------------------------------------------------- 1 | string('email')->index(); 17 | $table->string('token')->index(); 18 | $table->timestamp('created_at'); 19 | }); 20 | } 21 | 22 | /** 23 | * Reverse the migrations. 24 | * 25 | * @return void 26 | */ 27 | public function down() 28 | { 29 | Schema::drop('password_resets'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /database/migrations/2018_02_28_141331_add_posts_column_published_at.php: -------------------------------------------------------------------------------- 1 | dateTime('published_at')->nullable(); 18 | }); 19 | } 20 | 21 | /** 22 | * Reverse the migrations. 23 | * 24 | * @return void 25 | */ 26 | public function down() 27 | { 28 | Schema::table('posts', function (Blueprint $table) { 29 | $table->dropColumn('published_at'); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Passwords must be at least six characters and match the confirmation.', 17 | 'reset' => 'Your password has been reset!', 18 | 'sent' => 'We have e-mailed your password reset link!', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that e-mail address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 17 | $table->string('name'); 18 | $table->string('email')->unique(); 19 | $table->string('password'); 20 | $table->rememberToken(); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::drop('users'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton(SiteRepository::class); 30 | $this->app->when(SiteRepository::class)->needs(Filesystem::class)->give(function () { 31 | return app('filesystem')->disk('local'); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Events/PostCreated.php: -------------------------------------------------------------------------------- 1 | post = $post; 28 | } 29 | 30 | /** 31 | * Get the channels the event should broadcast on. 32 | * 33 | * @return \Illuminate\Broadcasting\Channel|array 34 | */ 35 | public function broadcastOn() 36 | { 37 | return new PrivateChannel('channel-name'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/JsonApi/Users/Schema.php: -------------------------------------------------------------------------------- 1 | getRouteKey(); 24 | } 25 | 26 | /** 27 | * @param User $resource 28 | * the domain record being serialized. 29 | * @return array 30 | */ 31 | public function getAttributes($resource) 32 | { 33 | return [ 34 | 'created-at' => $resource->created_at->toAtomString(), 35 | 'updated-at' => $resource->updated_at->toAtomString(), 36 | 'name' => $resource->name, 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/JsonApi/Tags/Schema.php: -------------------------------------------------------------------------------- 1 | getRouteKey(); 30 | } 31 | 32 | /** 33 | * @param Tag $resource 34 | * @return array 35 | */ 36 | public function getAttributes($resource) 37 | { 38 | return [ 39 | 'created-at' => $resource->created_at->toAtomString(), 40 | 'updated-at' => $resource->updated_at->toAtomString(), 41 | 'name' => $resource->name, 42 | ]; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /public/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ForgotPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/JsonApi/Users/Adapter.php: -------------------------------------------------------------------------------- 1 | command('inspire') 28 | // ->hourly(); 29 | } 30 | 31 | /** 32 | * Register the commands for the application. 33 | * 34 | * @return void 35 | */ 36 | protected function commands() 37 | { 38 | $this->load(__DIR__.'/Commands'); 39 | 40 | require base_path('routes/console.php'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /resources/assets/js/app.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * First we will load all of this project's JavaScript dependencies which 4 | * includes Vue and other libraries. It is a great starting point when 5 | * building robust, powerful web applications using Vue and Laravel. 6 | */ 7 | 8 | require('./bootstrap'); 9 | 10 | window.Vue = require('vue'); 11 | 12 | /** 13 | * Next, we will create a fresh Vue application instance and attach it to 14 | * the page. Then, you may begin adding components to this application 15 | * or customize the JavaScript scaffolding to fit your unique needs. 16 | */ 17 | 18 | // Vue.component( 19 | // 'passport-clients', 20 | // require('./components/passport/Clients.vue') 21 | // ); 22 | // 23 | // Vue.component( 24 | // 'passport-authorized-clients', 25 | // require('./components/passport/AuthorizedClients.vue') 26 | // ); 27 | 28 | Vue.component( 29 | 'passport-personal-access-tokens', 30 | require('./components/passport/PersonalAccessTokens.vue') 31 | ); 32 | 33 | const app = new Vue({ 34 | el: '#app' 35 | }); 36 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | 'Api'], function (Api $api) { 18 | $api->resource('comments', [ 19 | 'middleware' => 'json-api.auth:default', 20 | 'has-one' => ['post', 'created-by'], 21 | ]); 22 | $api->resource('posts', [ 23 | 'middleware' => 'json-api.auth:default', 24 | 'controller' => true, 25 | 'has-one' => 'author', 26 | 'has-many' => ['comments', 'tags'] 27 | ]); 28 | $api->resource('sites'); 29 | }); 30 | -------------------------------------------------------------------------------- /app/Providers/AuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | Policies\CommentPolicy::class, 22 | Post::class => Policies\PostPolicy::class, 23 | User::class => Policies\UserPolicy::class, 24 | ]; 25 | 26 | /** 27 | * Register any application authentication / authorization services. 28 | * 29 | * @param \Illuminate\Contracts\Auth\Access\Gate $gate 30 | * @return void 31 | */ 32 | public function boot(GateContract $gate) 33 | { 34 | $this->registerPolicies($gate); 35 | 36 | Passport::routes(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "npm run development", 5 | "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 6 | "watch": "npm run development -- --watch", 7 | "watch-poll": "npm run watch -- --watch-poll", 8 | "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", 9 | "prod": "npm run production", 10 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" 11 | }, 12 | "devDependencies": { 13 | "axios": "^0.18", 14 | "bootstrap": "^4.1.2", 15 | "cross-env": "^5.1", 16 | "jquery": "^3.2", 17 | "laravel-mix": "^2.0", 18 | "lodash": "^4.17.5", 19 | "popper.js": "^1.12", 20 | "vue": "^2.5.7" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /config/compile.php: -------------------------------------------------------------------------------- 1 | [ 17 | // 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled File Providers 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may list service providers which define a "compiles" function 26 | | that returns additional files that should be compiled, providing an 27 | | easy way to get common files from any packages you are utilizing. 28 | | 29 | */ 30 | 31 | 'providers' => [ 32 | // 33 | ], 34 | 35 | ]; 36 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/LoginController.php: -------------------------------------------------------------------------------- 1 | middleware('guest')->except('logout'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | ], 21 | 22 | 'ses' => [ 23 | 'key' => env('SES_KEY'), 24 | 'secret' => env('SES_SECRET'), 25 | 'region' => 'us-east-1', 26 | ], 27 | 28 | 'sparkpost' => [ 29 | 'secret' => env('SPARKPOST_SECRET'), 30 | ], 31 | 32 | 'stripe' => [ 33 | 'model' => App\User::class, 34 | 'key' => env('STRIPE_KEY'), 35 | 'secret' => env('STRIPE_SECRET'), 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ResetPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | realpath(base_path('resources/views')), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => realpath(storage_path('framework/views')), 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /app/Post.php: -------------------------------------------------------------------------------- 1 | belongsTo(User::class); 38 | } 39 | 40 | /** 41 | * @return HasMany 42 | */ 43 | public function comments() 44 | { 45 | return $this->hasMany(Comment::class); 46 | } 47 | 48 | /** 49 | * @return BelongsToMany 50 | */ 51 | public function tags() 52 | { 53 | return $this->belongsToMany(Tag::class); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/Feature 16 | 17 | 18 | 19 | ./tests/Unit 20 | 21 | 22 | 23 | 24 | ./app 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/Feature/CommentsTest.php: -------------------------------------------------------------------------------- 1 | create(); 18 | 19 | $self = "http://localhost/api/v1/comments/{$model->getKey()}"; 20 | 21 | $data = [ 22 | 'type' => 'comments', 23 | 'id' => (string) $model->getRouteKey(), 24 | 'attributes' => [ 25 | 'content' => $model->content, 26 | ], 27 | 'relationships' => [ 28 | 'post' => [ 29 | 'links' => [ 30 | 'self' => "$self/relationships/post", 31 | 'related' => "$self/post", 32 | ], 33 | ], 34 | 'created-by' => [ 35 | 'links' => [ 36 | 'self' => "$self/relationships/created-by", 37 | 'related' => "$self/created-by", 38 | ], 39 | ], 40 | ], 41 | ]; 42 | 43 | $this->doRead($model)->assertRead($data); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /database/migrations/2016_09_03_153707_create-tags-table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->timestamps(); 19 | $table->string('name'); 20 | }); 21 | 22 | Schema::create('post_tag', function (Blueprint $table) { 23 | $table->increments('id'); 24 | $table->integer('post_id')->unsigned(); 25 | $table->integer('tag_id')->unsigned(); 26 | 27 | $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade')->onUpdate('cascade'); 28 | $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade')->onUpdate('cascade'); 29 | }); 30 | } 31 | 32 | /** 33 | * Reverse the migrations. 34 | * 35 | * @return void 36 | */ 37 | public function down() 38 | { 39 | Schema::drop('post_tag'); 40 | Schema::drop('tags'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /resources/views/errors/503.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Be right back. 5 | 6 | 7 | 8 | 39 | 40 | 41 |
42 |
43 |
Be right back.
44 |
45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /database/seeds/PostSeeder.php: -------------------------------------------------------------------------------- 1 | create()->map(function (User $person) { 25 | return $person->getKey(); 26 | })->all(); 27 | 28 | $user = function () use ($faker, $users) { 29 | return $faker->randomElement($users); 30 | }; 31 | 32 | /** @var Collection $tags */ 33 | $tags = factory(Tag::class, 10)->create(); 34 | 35 | factory(Post::class, 50)->create([ 36 | 'author_id' => $user, 37 | ])->each(function (Post $post) use ($faker, $user, $tags) { 38 | factory(Comment::class, $faker->numberBetween(1, 10))->create([ 39 | 'post_id' => $post->getKey(), 40 | 'user_id' => $user, 41 | ]); 42 | 43 | $post->tags()->save($tags->random()); 44 | }); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/JsonApi/Comments/Adapter.php: -------------------------------------------------------------------------------- 1 | belongsTo(); 31 | } 32 | 33 | /** 34 | * @return BelongsTo 35 | */ 36 | protected function createdBy() 37 | { 38 | return $this->belongsTo('user'); 39 | } 40 | 41 | /** 42 | * @inheritDoc 43 | */ 44 | protected function filter($query, Collection $filters) 45 | { 46 | // TODO: Implement filter() method. 47 | } 48 | 49 | /** 50 | * @param Comment $comment 51 | */ 52 | protected function creating(Comment $comment): void 53 | { 54 | $comment->user()->associate(Auth::user()); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /app/Policies/UserPolicy.php: -------------------------------------------------------------------------------- 1 | is($model); 45 | } 46 | 47 | /** 48 | * Determine whether the user can delete the model. 49 | * 50 | * @param \App\User $user 51 | * @param \App\User $model 52 | * @return mixed 53 | */ 54 | public function delete(User $user, User $model) 55 | { 56 | return $this->update($user, $model); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/Policies/PostPolicy.php: -------------------------------------------------------------------------------- 1 | is($post->author); 46 | } 47 | 48 | /** 49 | * Determine whether the user can delete the post. 50 | * 51 | * @param \App\User $user 52 | * @param \App\Post $post 53 | * @return mixed 54 | */ 55 | public function delete(User $user, Post $post) 56 | { 57 | return $this->update($user, $post); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/Policies/CommentPolicy.php: -------------------------------------------------------------------------------- 1 | is($comment->user); 46 | } 47 | 48 | /** 49 | * Determine whether the user can delete the comment. 50 | * 51 | * @param \App\User $user 52 | * @param \App\Comment $comment 53 | * @return mixed 54 | */ 55 | public function delete(User $user, Comment $comment) 56 | { 57 | return $this->update($user, $comment); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /database/factories/ModelFactory.php: -------------------------------------------------------------------------------- 1 | define(App\User::class, function (Faker $faker) { 10 | return [ 11 | 'name' => $faker->name, 12 | 'email' => $faker->safeEmail, 13 | 'password' => bcrypt(str_random(10)), 14 | 'remember_token' => str_random(10), 15 | ]; 16 | }); 17 | 18 | /** Post */ 19 | $factory->define(App\Post::class, function (Faker $faker) { 20 | return [ 21 | 'title' => $faker->sentence(3), 22 | 'slug' => $faker->slug(), 23 | 'content' => $faker->paragraphs(3, true), 24 | 'published_at' => $faker->dateTime, 25 | 'author_id' => function () { 26 | return factory(App\User::class)->create()->getKey(); 27 | }, 28 | ]; 29 | }); 30 | 31 | /** Comment */ 32 | $factory->define(App\Comment::class, function (Faker $faker) { 33 | return [ 34 | 'content' => $faker->paragraph, 35 | 'post_id' => function () { 36 | return factory(App\Post::class)->create()->getKey(); 37 | }, 38 | 'user_id' => function () { 39 | return factory(App\User::class)->create()->getKey(); 40 | }, 41 | ]; 42 | }); 43 | 44 | /** Tag */ 45 | $factory->define(App\Tag::class, function (Faker $faker) { 46 | return [ 47 | 'name' => $faker->country, 48 | ]; 49 | }); 50 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'pusher'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Broadcast Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may define all of the broadcast connections that will be used 24 | | to broadcast events to other systems or over websockets. Samples of 25 | | each available type of connection are provided inside this array. 26 | | 27 | */ 28 | 29 | 'connections' => [ 30 | 31 | 'pusher' => [ 32 | 'driver' => 'pusher', 33 | 'key' => env('PUSHER_KEY'), 34 | 'secret' => env('PUSHER_SECRET'), 35 | 'app_id' => env('PUSHER_APP_ID'), 36 | 'options' => [ 37 | // 38 | ], 39 | ], 40 | 41 | 'redis' => [ 42 | 'driver' => 'redis', 43 | 'connection' => 'default', 44 | ], 45 | 46 | 'log' => [ 47 | 'driver' => 'log', 48 | ], 49 | 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /database/migrations/2016_06_04_063426_create-posts-and-comments-tables.php: -------------------------------------------------------------------------------- 1 | increments('id'); 17 | $table->timestamps(); 18 | $table->integer('author_id')->unsigned(); 19 | $table->string('title'); 20 | $table->string('slug'); 21 | $table->text('content'); 22 | 23 | $table->unique('slug'); 24 | $table->foreign('author_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade'); 25 | }); 26 | 27 | Schema::create('comments', function (Blueprint $table) { 28 | $table->increments('id'); 29 | $table->timestamps(); 30 | $table->integer('post_id')->unsigned(); 31 | $table->integer('user_id')->unsigned(); 32 | $table->text('content'); 33 | 34 | $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade')->onUpdate('cascade'); 35 | $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade'); 36 | }); 37 | } 38 | 39 | /** 40 | * Reverse the migrations. 41 | * 42 | * @return void 43 | */ 44 | public function down() 45 | { 46 | Schema::drop('comments'); 47 | Schema::drop('posts'); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | isJsonApi($request, $exception)) { 57 | return $this->renderJsonApi($request, $exception); 58 | } 59 | 60 | return parent::render($request, $exception); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/JsonApi/Posts/Validators.php: -------------------------------------------------------------------------------- 1 | getKey(); 45 | } 46 | 47 | return [ 48 | 'title' => "required|string|between:1,255", 49 | 'content' => "required|string|min:1", 50 | 'slug' => "required|alpha_dash|$slugUnique", 51 | 'tags' => 'array', 52 | 'tags.*.type' => 'in:tags', 53 | ]; 54 | } 55 | 56 | /** 57 | * @return array 58 | */ 59 | protected function queryRules(): array 60 | { 61 | return [ 62 | 'filter.title' => 'string|min:1', 63 | 'filter.slug' => 'sometimes|required|alpha_dash', 64 | 'page.number' => 'integer|min:1', 65 | 'page.size' => 'integer|between:1,50', 66 | ]; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 34 | 35 | $status = $kernel->handle( 36 | $input = new Symfony\Component\Console\Input\ArgvInput, 37 | new Symfony\Component\Console\Output\ConsoleOutput 38 | ); 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Shutdown The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once Artisan has finished running, we will fire off the shutdown events 46 | | so that any final work may be done by the application before we shut 47 | | down the process. This is the last thing to happen to the request. 48 | | 49 | */ 50 | 51 | $kernel->terminate($input, $status); 52 | 53 | exit($status); 54 | -------------------------------------------------------------------------------- /app/JsonApi/Comments/Schema.php: -------------------------------------------------------------------------------- 1 | getRouteKey(); 23 | } 24 | 25 | /** 26 | * @param Comment $resource 27 | * @return array 28 | */ 29 | public function getAttributes($resource) 30 | { 31 | return [ 32 | 'created-at' => $resource->created_at->toAtomString(), 33 | 'updated-at' => $resource->updated_at->toAtomString(), 34 | 'content' => $resource->content, 35 | ]; 36 | } 37 | 38 | /** 39 | * @param Comment $resource 40 | * @param bool $isPrimary 41 | * @param array $includedRelationships 42 | * @return array 43 | */ 44 | public function getRelationships($resource, $isPrimary, array $includedRelationships) 45 | { 46 | return [ 47 | 'post' => [ 48 | self::SHOW_SELF => true, 49 | self::SHOW_RELATED => true, 50 | self::SHOW_DATA => isset($includedRelationships['post']), 51 | self::DATA => function () use ($resource) { 52 | return $resource->post; 53 | }, 54 | ], 55 | 'created-by' => [ 56 | self::SHOW_SELF => true, 57 | self::SHOW_RELATED => true, 58 | self::SHOW_DATA => isset($includedRelationships['created-by']), 59 | self::DATA => function () use ($resource) { 60 | return $resource->user; 61 | }, 62 | ], 63 | ]; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /resources/assets/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | 2 | window._ = require('lodash'); 3 | window.Popper = require('popper.js').default; 4 | 5 | /** 6 | * We'll load jQuery and the Bootstrap jQuery plugin which provides support 7 | * for JavaScript based Bootstrap features such as modals and tabs. This 8 | * code may be modified to fit the specific needs of your application. 9 | */ 10 | 11 | try { 12 | window.$ = window.jQuery = require('jquery'); 13 | 14 | require('bootstrap'); 15 | } catch (e) {} 16 | 17 | /** 18 | * We'll load the axios HTTP library which allows us to easily issue requests 19 | * to our Laravel back-end. This library automatically handles sending the 20 | * CSRF token as a header based on the value of the "XSRF" token cookie. 21 | */ 22 | 23 | window.axios = require('axios'); 24 | 25 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 26 | 27 | /** 28 | * Next we will register the CSRF Token as a common header with Axios so that 29 | * all outgoing HTTP requests automatically have it attached. This is just 30 | * a simple convenience so we don't have to attach every token manually. 31 | */ 32 | 33 | let token = document.head.querySelector('meta[name="csrf-token"]'); 34 | 35 | if (token) { 36 | window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; 37 | } else { 38 | console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token'); 39 | } 40 | 41 | /** 42 | * Echo exposes an expressive API for subscribing to channels and listening 43 | * for events that are broadcast by Laravel. Echo and event broadcasting 44 | * allows your team to easily build robust real-time web applications. 45 | */ 46 | 47 | // import Echo from 'laravel-echo' 48 | 49 | // window.Pusher = require('pusher-js'); 50 | 51 | // window.Echo = new Echo({ 52 | // broadcaster: 'pusher', 53 | // key: process.env.MIX_PUSHER_APP_KEY, 54 | // cluster: process.env.MIX_PUSHER_APP_CLUSTER, 55 | // encrypted: true 56 | // }); 57 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | mapApiRoutes(); 39 | 40 | $this->mapWebRoutes(); 41 | 42 | // 43 | } 44 | 45 | /** 46 | * Define the "web" routes for the application. 47 | * 48 | * These routes all receive session state, CSRF protection, etc. 49 | * 50 | * @return void 51 | */ 52 | protected function mapWebRoutes() 53 | { 54 | Route::group([ 55 | 'middleware' => 'web', 56 | 'namespace' => $this->namespace, 57 | ], function ($router) { 58 | require base_path('routes/web.php'); 59 | }); 60 | } 61 | 62 | /** 63 | * Define the "api" routes for the application. 64 | * 65 | * These routes are typically stateless. 66 | * 67 | * @return void 68 | */ 69 | protected function mapApiRoutes() 70 | { 71 | Route::group([ 72 | 'middleware' => 'api', 73 | 'namespace' => $this->namespace 74 | ], function ($router) { 75 | require base_path('routes/api.php'); 76 | }); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | define('LARAVEL_START', microtime(true)); 11 | 12 | /* 13 | |-------------------------------------------------------------------------- 14 | | Register The Auto Loader 15 | |-------------------------------------------------------------------------- 16 | | 17 | | Composer provides a convenient, automatically generated class loader for 18 | | our application. We just need to utilize it! We'll simply require it 19 | | into the script here so that we don't have to worry about manual 20 | | loading any of our classes later on. It feels great to relax. 21 | | 22 | */ 23 | 24 | require __DIR__.'/../vendor/autoload.php'; 25 | 26 | /* 27 | |-------------------------------------------------------------------------- 28 | | Turn On The Lights 29 | |-------------------------------------------------------------------------- 30 | | 31 | | We need to illuminate PHP development, so let us turn on the lights. 32 | | This bootstraps the framework and gets it ready for use, then it 33 | | will load up this application so that we can run it and send 34 | | the responses back to the browser and delight our users. 35 | | 36 | */ 37 | 38 | $app = require_once __DIR__.'/../bootstrap/app.php'; 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Run The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once we have the application, we can handle the incoming request 46 | | through the kernel, and send the associated response back to 47 | | the client's browser allowing them to enjoy the creative 48 | | and wonderful application we have prepared for them. 49 | | 50 | */ 51 | 52 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 53 | 54 | $response = $kernel->handle( 55 | $request = Illuminate\Http\Request::capture() 56 | ); 57 | 58 | $response->send(); 59 | 60 | $kernel->terminate($request, $response); 61 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cloudcreativity/demo-laravel-json-api", 3 | "description": "Demo Laravel application using the cloudcreativity/laravel-json-api package.", 4 | "keywords": [ 5 | "laravel", 6 | "json-api", 7 | "cloudcreativity" 8 | ], 9 | "license": "Apache-2.0", 10 | "type": "project", 11 | "require": { 12 | "php": "^7.1", 13 | "ext-json": "*", 14 | "cloudcreativity/laravel-json-api": "^1.5", 15 | "doctrine/dbal": "^2.6", 16 | "fideloper/proxy": "^4.0", 17 | "laravel/framework": "5.6.*", 18 | "laravel/passport": "^6.0", 19 | "laravel/tinker": "^1.0" 20 | }, 21 | "require-dev": { 22 | "cloudcreativity/json-api-testing": "^1.1", 23 | "filp/whoops": "^2.1", 24 | "fzaninotto/faker": "~1.4", 25 | "laravel/homestead": "^9.2", 26 | "mockery/mockery": "^1.0", 27 | "phpunit/phpunit": "^7.0" 28 | }, 29 | "autoload": { 30 | "classmap": [ 31 | "database/seeds", 32 | "database/factories" 33 | ], 34 | "psr-4": { 35 | "App\\": "app/" 36 | } 37 | }, 38 | "autoload-dev": { 39 | "psr-4": { 40 | "Tests\\": "tests/" 41 | } 42 | }, 43 | "extra": { 44 | "laravel": { 45 | "dont-discover": [ 46 | ] 47 | } 48 | }, 49 | "scripts": { 50 | "post-root-package-install": [ 51 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 52 | ], 53 | "post-create-project-cmd": [ 54 | "@php artisan key:generate" 55 | ], 56 | "post-autoload-dump": [ 57 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 58 | "@php artisan package:discover" 59 | ] 60 | }, 61 | "minimum-stability": "stable", 62 | "prefer-stable": true, 63 | "config": { 64 | "preferred-install": "dist", 65 | "sort-packages": true, 66 | "optimize-autoload": true 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /resources/views/auth/passwords/email.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
{{ __('Reset Password') }}
9 | 10 |
11 | @if (session('status')) 12 |
13 | {{ session('status') }} 14 |
15 | @endif 16 | 17 |
18 | @csrf 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | @if ($errors->has('email')) 27 | 28 | {{ $errors->first('email') }} 29 | 30 | @endif 31 |
32 |
33 | 34 |
35 |
36 | 39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | @endsection 48 | -------------------------------------------------------------------------------- /tests/Feature/SitesTest.php: -------------------------------------------------------------------------------- 1 | create()); 24 | } 25 | 26 | public function testCreate() 27 | { 28 | // ensure 'my-site' doesn't exist before creating it... 29 | app(SiteRepository::class)->remove('my-site'); 30 | 31 | $data = [ 32 | 'type' => 'sites', 33 | 'id' => 'my-site', 34 | 'attributes' => [ 35 | 'name' => 'My Blog', 36 | 'domain' => 'http://blog.example.com', 37 | ], 38 | ]; 39 | 40 | $id = $this->doCreate($data)->assertCreatedWithId($data); 41 | $this->assertEquals('my-site', $id); 42 | 43 | return $data; 44 | } 45 | 46 | /** 47 | * @param array $expected 48 | * @depends testCreate 49 | */ 50 | public function testRead(array $expected) 51 | { 52 | $this->doRead('my-site')->assertRead($expected); 53 | } 54 | 55 | /** 56 | * @depends testCreate 57 | */ 58 | public function testUpdate() 59 | { 60 | $data = [ 61 | 'type' => 'sites', 62 | 'id' => 'my-site', 63 | 'attributes' => [ 64 | 'name' => 'My New Blog', 65 | ], 66 | ]; 67 | 68 | $expected = $data; 69 | $expected['attributes']['domain'] = 'http://blog.example.com'; 70 | 71 | $this->doUpdate($data)->assertUpdated($expected); 72 | } 73 | 74 | /** 75 | * @depends testCreate 76 | */ 77 | public function testDelete() 78 | { 79 | $this->doDelete('my-site')->assertDeleted(); 80 | $this->assertNull(app(SiteRepository::class)->find('my-site')); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisterController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 41 | } 42 | 43 | /** 44 | * Get a validator for an incoming registration request. 45 | * 46 | * @param array $data 47 | * @return \Illuminate\Contracts\Validation\Validator 48 | */ 49 | protected function validator(array $data) 50 | { 51 | return Validator::make($data, [ 52 | 'name' => 'required|string|max:255', 53 | 'email' => 'required|string|email|max:255|unique:users', 54 | 'password' => 'required|string|min:6|confirmed', 55 | ]); 56 | } 57 | 58 | /** 59 | * Create a new user instance after a valid registration. 60 | * 61 | * @param array $data 62 | * @return \App\User 63 | */ 64 | protected function create(array $data) 65 | { 66 | return User::create([ 67 | 'name' => $data['name'], 68 | 'email' => $data['email'], 69 | 'password' => Hash::make($data['password']), 70 | ]); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Log Channels 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the log channels for your application. Out of 24 | | the box, Laravel uses the Monolog PHP logging library. This gives 25 | | you a variety of powerful log handlers / formatters to utilize. 26 | | 27 | | Available Drivers: "single", "daily", "slack", "syslog", 28 | | "errorlog", "custom", "stack" 29 | | 30 | */ 31 | 32 | 'channels' => [ 33 | 'stack' => [ 34 | 'driver' => 'stack', 35 | 'channels' => ['single'], 36 | ], 37 | 38 | 'single' => [ 39 | 'driver' => 'single', 40 | 'path' => storage_path('logs/laravel.log'), 41 | 'level' => 'debug', 42 | ], 43 | 44 | 'daily' => [ 45 | 'driver' => 'daily', 46 | 'path' => storage_path('logs/laravel.log'), 47 | 'level' => 'debug', 48 | 'days' => 7, 49 | ], 50 | 51 | 'slack' => [ 52 | 'driver' => 'slack', 53 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 54 | 'username' => 'Laravel Log', 55 | 'emoji' => ':boom:', 56 | 'level' => 'critical', 57 | ], 58 | 59 | 'syslog' => [ 60 | 'driver' => 'syslog', 61 | 'level' => 'debug', 62 | ], 63 | 64 | 'errorlog' => [ 65 | 'driver' => 'errorlog', 66 | 'level' => 'debug', 67 | ], 68 | ], 69 | 70 | ]; 71 | -------------------------------------------------------------------------------- /app/Http/Kernel.php: -------------------------------------------------------------------------------- 1 | [ 31 | \App\Http\Middleware\EncryptCookies::class, 32 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 33 | \Illuminate\Session\Middleware\StartSession::class, 34 | // \Illuminate\Session\Middleware\AuthenticateSession::class, 35 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 36 | \App\Http\Middleware\VerifyCsrfToken::class, 37 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 38 | ], 39 | 40 | 'api' => [ 41 | 'throttle:60,1', 42 | 'bindings', 43 | ], 44 | ]; 45 | 46 | /** 47 | * The application's route middleware. 48 | * 49 | * These middleware may be assigned to groups or used individually. 50 | * 51 | * @var array 52 | */ 53 | protected $routeMiddleware = [ 54 | 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 55 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 56 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 57 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 58 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 59 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 60 | ]; 61 | } 62 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DRIVER', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Cloud Filesystem Disk 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Many applications store files both locally and in the cloud. For this 24 | | reason, you may specify a default "cloud" driver here. This driver 25 | | will be bound as the Cloud disk implementation in the container. 26 | | 27 | */ 28 | 29 | 'cloud' => env('FILESYSTEM_CLOUD', 's3'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Filesystem Disks 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here you may configure as many filesystem "disks" as you wish, and you 37 | | may even configure multiple disks of the same driver. Defaults have 38 | | been setup for each driver as an example of the required options. 39 | | 40 | | Supported Drivers: "local", "ftp", "s3", "rackspace" 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'public' => [ 52 | 'driver' => 'local', 53 | 'root' => storage_path('app/public'), 54 | 'url' => env('APP_URL').'/storage', 55 | 'visibility' => 'public', 56 | ], 57 | 58 | 's3' => [ 59 | 'driver' => 's3', 60 | 'key' => env('AWS_KEY'), 61 | 'secret' => env('AWS_SECRET'), 62 | 'region' => env('AWS_REGION'), 63 | 'bucket' => env('AWS_BUCKET'), 64 | ], 65 | 66 | ], 67 | 68 | ]; 69 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Cache Stores 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may define all of the cache "stores" for your application as 24 | | well as their drivers. You may even define multiple stores for the 25 | | same cache driver to group types of items stored in your caches. 26 | | 27 | */ 28 | 29 | 'stores' => [ 30 | 31 | 'apc' => [ 32 | 'driver' => 'apc', 33 | ], 34 | 35 | 'array' => [ 36 | 'driver' => 'array', 37 | ], 38 | 39 | 'database' => [ 40 | 'driver' => 'database', 41 | 'table' => 'cache', 42 | 'connection' => null, 43 | ], 44 | 45 | 'file' => [ 46 | 'driver' => 'file', 47 | 'path' => storage_path('framework/cache'), 48 | ], 49 | 50 | 'memcached' => [ 51 | 'driver' => 'memcached', 52 | 'servers' => [ 53 | [ 54 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 55 | 'port' => env('MEMCACHED_PORT', 11211), 56 | 'weight' => 100, 57 | ], 58 | ], 59 | ], 60 | 61 | 'redis' => [ 62 | 'driver' => 'redis', 63 | 'connection' => 'default', 64 | ], 65 | 66 | ], 67 | 68 | /* 69 | |-------------------------------------------------------------------------- 70 | | Cache Key Prefix 71 | |-------------------------------------------------------------------------- 72 | | 73 | | When utilizing a RAM based store such as APC or Memcached, there might 74 | | be other applications utilizing the same cache. So, we'll specify a 75 | | value to get prefixed to all our keys so we can avoid collisions. 76 | | 77 | */ 78 | 79 | 'prefix' => 'laravel', 80 | 81 | ]; 82 | -------------------------------------------------------------------------------- /app/JsonApi/Posts/Adapter.php: -------------------------------------------------------------------------------- 1 | 1, 41 | ]; 42 | 43 | /** 44 | * Adapter constructor. 45 | * 46 | * @param StandardStrategy $paging 47 | */ 48 | public function __construct(StandardStrategy $paging) 49 | { 50 | parent::__construct(new Post(), $paging); 51 | } 52 | 53 | /** 54 | * @return BelongsTo 55 | */ 56 | protected function author() 57 | { 58 | return $this->belongsTo(); 59 | } 60 | 61 | /** 62 | * @return HasMany 63 | */ 64 | protected function comments() 65 | { 66 | return $this->hasMany(); 67 | } 68 | 69 | /** 70 | * @return HasMany 71 | */ 72 | protected function tags() 73 | { 74 | return $this->hasMany(); 75 | } 76 | 77 | /** 78 | * @param Post $post 79 | */ 80 | protected function creating(Post $post): void 81 | { 82 | $post->author()->associate(Auth::user()); 83 | } 84 | 85 | /** 86 | * @inheritdoc 87 | */ 88 | protected function filter($query, Collection $filters) 89 | { 90 | if ($filters->has('title')) { 91 | $query->where('posts.title', 'like', '%' . $filters->get('title') . '%'); 92 | } 93 | 94 | if ($filters->has('slug')) { 95 | $query->where('posts.slug', $filters->get('slug')); 96 | } 97 | } 98 | 99 | /** 100 | * @inheritdoc 101 | */ 102 | protected function isSearchOne(Collection $filters) 103 | { 104 | return $filters->has('slug'); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /app/SiteRepository.php: -------------------------------------------------------------------------------- 1 | disk = $disk; 29 | } 30 | 31 | /** 32 | * @param $slug 33 | * @return Site|null 34 | */ 35 | public function find($slug) 36 | { 37 | $this->load(); 38 | 39 | if ($data = $this->sites[$slug] ?? null) { 40 | return Site::create($slug, $data); 41 | } 42 | 43 | return null; 44 | } 45 | 46 | /** 47 | * @return array 48 | */ 49 | public function findAll(): array 50 | { 51 | return iterator_to_array($this->all()); 52 | } 53 | 54 | /** 55 | * @param Site $site 56 | */ 57 | public function store(Site $site) 58 | { 59 | $this->load(); 60 | $this->sites[$site->getSlug()] = $site->toArray(); 61 | $this->write(); 62 | } 63 | 64 | /** 65 | * @param Site|string $site 66 | */ 67 | public function remove($site) 68 | { 69 | $slug = ($site instanceof Site) ? $site->getSlug() : $site; 70 | 71 | $this->load(); 72 | unset($this->sites[$slug]); 73 | $this->write(); 74 | } 75 | 76 | /** 77 | * @return Generator 78 | */ 79 | public function all(): Generator 80 | { 81 | $this->load(); 82 | 83 | foreach ($this->sites as $slug => $values) { 84 | yield $slug => Site::create($slug, $values); 85 | } 86 | } 87 | 88 | /** 89 | * @return void 90 | */ 91 | private function load() 92 | { 93 | if (is_array($this->sites)) { 94 | return; 95 | } 96 | 97 | $data = $this->disk->exists('sites.json') ? $this->disk->get('sites.json') : ''; 98 | $this->sites = (array) json_decode($data, true); 99 | } 100 | 101 | /** 102 | * @return void 103 | */ 104 | private function write() 105 | { 106 | if (!is_array($this->sites)) { 107 | return; 108 | } 109 | 110 | $data = json_encode($this->sites, JSON_PRETTY_PRINT); 111 | $this->disk->put('sites.json', $data); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /app/JsonApi/Posts/Schema.php: -------------------------------------------------------------------------------- 1 | getRouteKey(); 42 | } 43 | 44 | /** 45 | * @param Post $resource 46 | * @return array 47 | */ 48 | public function getAttributes($resource) 49 | { 50 | $publishedAt = $resource->published_at; 51 | 52 | return [ 53 | 'created-at' => $resource->created_at->toAtomString(), 54 | 'updated-at' => $resource->updated_at->toAtomString(), 55 | 'title' => $resource->title, 56 | 'slug' => $resource->slug, 57 | 'content' => $resource->content, 58 | 'published-at' => $publishedAt ? $publishedAt->toAtomString() : null, 59 | ]; 60 | } 61 | 62 | /** 63 | * @param Post $resource 64 | * @param bool $isPrimary 65 | * @param array $includedRelationships 66 | * @return array 67 | */ 68 | public function getRelationships($resource, $isPrimary, array $includedRelationships) 69 | { 70 | return [ 71 | 'author' => [ 72 | self::SHOW_SELF => true, 73 | self::SHOW_RELATED => true, 74 | self::SHOW_DATA => isset($includedRelationships['author']), 75 | self::DATA => function () use ($resource) { 76 | return $resource->author; 77 | }, 78 | ], 79 | 'comments' => [ 80 | self::SHOW_SELF => true, 81 | self::SHOW_RELATED => true, 82 | self::SHOW_DATA => false, 83 | ], 84 | 'tags' => [ 85 | self::SHOW_SELF => true, 86 | self::SHOW_RELATED => true, 87 | self::SHOW_DATA => isset($includedRelationships['tags']), 88 | self::DATA => function () use ($resource) { 89 | return $resource->tags; 90 | }, 91 | ], 92 | ]; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /app/JsonApi/Sites/Authorizer.php: -------------------------------------------------------------------------------- 1 | authenticate(); 27 | } 28 | 29 | /** 30 | * Authorize a resource create request. 31 | * 32 | * @param string $type 33 | * the domain record type. 34 | * @param Request $request 35 | * the inbound request. 36 | * @return void 37 | * @throws AuthenticationException|AuthorizationException 38 | * if the request is not authorized. 39 | */ 40 | public function create($type, $request) 41 | { 42 | $this->authenticate(); 43 | } 44 | 45 | /** 46 | * Authorize a resource read request. 47 | * 48 | * @param object $record 49 | * the domain record. 50 | * @param Request $request 51 | * the inbound request. 52 | * @return void 53 | * @throws AuthenticationException|AuthorizationException 54 | * if the request is not authorized. 55 | */ 56 | public function read($record, $request) 57 | { 58 | $this->authenticate(); 59 | } 60 | 61 | /** 62 | * Authorize a resource update request. 63 | * 64 | * @param object $record 65 | * the domain record. 66 | * @param Request $request 67 | * the inbound request. 68 | * @return void 69 | * @throws AuthenticationException|AuthorizationException 70 | * if the request is not authorized. 71 | */ 72 | public function update($record, $request) 73 | { 74 | $this->read($record, $request); 75 | } 76 | 77 | /** 78 | * Authorize a resource read request. 79 | * 80 | * @param object $record 81 | * the domain record. 82 | * @param Request $request 83 | * the inbound request. 84 | * @return void 85 | * @throws AuthenticationException|AuthorizationException 86 | * if the request is not authorized. 87 | */ 88 | public function delete($record, $request) 89 | { 90 | $this->read($record, $request); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_DRIVER', 'sync'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Queue Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may configure the connection information for each server that 26 | | is used by your application. A default configuration has been added 27 | | for each back-end shipped with Laravel. You are free to add more. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'table' => 'jobs', 40 | 'queue' => 'default', 41 | 'expire' => 60, 42 | ], 43 | 44 | 'beanstalkd' => [ 45 | 'driver' => 'beanstalkd', 46 | 'host' => 'localhost', 47 | 'queue' => 'default', 48 | 'ttr' => 60, 49 | ], 50 | 51 | 'sqs' => [ 52 | 'driver' => 'sqs', 53 | 'key' => 'your-public-key', 54 | 'secret' => 'your-secret-key', 55 | 'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id', 56 | 'queue' => 'your-queue-name', 57 | 'region' => 'us-east-1', 58 | ], 59 | 60 | 'redis' => [ 61 | 'driver' => 'redis', 62 | 'connection' => 'default', 63 | 'queue' => 'default', 64 | 'expire' => 60, 65 | ], 66 | 67 | ], 68 | 69 | /* 70 | |-------------------------------------------------------------------------- 71 | | Failed Queue Jobs 72 | |-------------------------------------------------------------------------- 73 | | 74 | | These options configure the behavior of failed queue job logging so you 75 | | can control which database and table are used to store the jobs that 76 | | have failed. You may change them to any database / table you wish. 77 | | 78 | */ 79 | 80 | 'failed' => [ 81 | 'database' => env('DB_CONNECTION', 'mysql'), 82 | 'table' => 'failed_jobs', 83 | ], 84 | 85 | ]; 86 | -------------------------------------------------------------------------------- /app/JsonApi/DefaultAuthorizer.php: -------------------------------------------------------------------------------- 1 | can('create', $type); 44 | } 45 | 46 | /** 47 | * Authorize a resource read request. 48 | * 49 | * @param object $record 50 | * the domain record. 51 | * @param Request $request 52 | * the inbound request. 53 | * @return void 54 | * @throws AuthenticationException|AuthorizationException 55 | * if the request is not authorized. 56 | */ 57 | public function read($record, $request) 58 | { 59 | // no-op, records are available without signing in. 60 | } 61 | 62 | /** 63 | * Authorize a resource update request. 64 | * 65 | * @param object $record 66 | * the domain record. 67 | * @param Request $request 68 | * the inbound request. 69 | * @return void 70 | * @throws AuthenticationException|AuthorizationException 71 | * if the request is not authorized. 72 | */ 73 | public function update($record, $request) 74 | { 75 | // check via policies 76 | $this->can('update', $record); 77 | } 78 | 79 | /** 80 | * Authorize a resource read request. 81 | * 82 | * @param object $record 83 | * the domain record. 84 | * @param Request $request 85 | * the inbound request. 86 | * @return void 87 | * @throws AuthenticationException|AuthorizationException 88 | * if the request is not authorized. 89 | */ 90 | public function delete($record, $request) 91 | { 92 | // check via policies 93 | $this->can('delete', $record); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /app/Site.php: -------------------------------------------------------------------------------- 1 | exchangeArray($values); 34 | 35 | return $site; 36 | } 37 | 38 | /** 39 | * Site constructor. 40 | * 41 | * @param string $slug 42 | */ 43 | public function __construct(string $slug) 44 | { 45 | if (empty($slug)) { 46 | throw new InvalidArgumentException('Expecting a non-empty slug'); 47 | } 48 | 49 | $this->slug = $slug; 50 | } 51 | 52 | /** 53 | * @return string 54 | */ 55 | public function getSlug(): string 56 | { 57 | return $this->slug; 58 | } 59 | 60 | /** 61 | * @param mixed $domain 62 | * @return $this 63 | */ 64 | public function setDomain(string $domain) 65 | { 66 | $this->domain = $domain; 67 | 68 | return $this; 69 | } 70 | 71 | /** 72 | * @return string 73 | */ 74 | public function getDomain(): string 75 | { 76 | return (string) $this->domain; 77 | } 78 | 79 | /** 80 | * @param string $name 81 | * @return $this 82 | */ 83 | public function setName(string $name) 84 | { 85 | $this->name = $name; 86 | 87 | return $this; 88 | } 89 | 90 | /** 91 | * @return string 92 | */ 93 | public function getName(): string 94 | { 95 | return (string) $this->name; 96 | } 97 | 98 | /** 99 | * @param array $values 100 | * @return $this 101 | */ 102 | public function exchangeArray(array $values) 103 | { 104 | if ($domain = $values['domain'] ?? null) { 105 | $this->setDomain($domain); 106 | } 107 | 108 | if ($name = $values['name'] ?? null) { 109 | $this->setName($name); 110 | } 111 | 112 | return $this; 113 | } 114 | 115 | /** 116 | * @return array 117 | */ 118 | public function toArray(): array 119 | { 120 | return [ 121 | 'domain' => $this->getDomain(), 122 | 'name' => $this->getName(), 123 | ]; 124 | } 125 | 126 | /** 127 | * @return void 128 | */ 129 | public function save() 130 | { 131 | app(SiteRepository::class)->store($this); 132 | } 133 | 134 | /** 135 | * @return void 136 | */ 137 | public function delete() 138 | { 139 | app(SiteRepository::class)->remove($this); 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /app/JsonApi/Sites/Adapter.php: -------------------------------------------------------------------------------- 1 | repository = $repository; 29 | } 30 | 31 | /** 32 | * @inheritDoc 33 | */ 34 | public function query(EncodingParametersInterface $parameters) 35 | { 36 | return $this->repository->all(); 37 | } 38 | 39 | /** 40 | * @inheritdoc 41 | */ 42 | public function exists($resourceId) 43 | { 44 | return !is_null($this->find($resourceId)); 45 | } 46 | 47 | /** 48 | * @inheritdoc 49 | */ 50 | public function find($resourceId) 51 | { 52 | return $this->repository->find($resourceId); 53 | } 54 | 55 | /** 56 | * @inheritdoc 57 | */ 58 | public function findMany(array $resourceIds) 59 | { 60 | return collect($resourceIds)->map(function ($resourceId) { 61 | return $this->find($resourceId); 62 | })->all(); 63 | } 64 | 65 | /** 66 | * @param Site $record 67 | * @return bool 68 | */ 69 | public function destroy($record) 70 | { 71 | $record->delete(); 72 | 73 | return true; 74 | } 75 | 76 | /** 77 | * @inheritdoc 78 | */ 79 | protected function createRecord(ResourceObject $resource) 80 | { 81 | return new Site($resource['id']); // client generated id. 82 | } 83 | 84 | /** 85 | * @param Site $record 86 | * @param Collection $attributes 87 | */ 88 | protected function fillAttributes($record, Collection $attributes) 89 | { 90 | $attributes->only(['name', 'domain'])->each(function ($value, $key) use ($record) { 91 | $this->fillAttribute($record, $key, $value); 92 | }); 93 | } 94 | 95 | /** 96 | * @param Site $record 97 | * @return object 98 | */ 99 | protected function persist($record) 100 | { 101 | $record->save(); 102 | 103 | return $record; 104 | } 105 | 106 | /** 107 | * @param Site $record 108 | * @param string $attrKey 109 | * @param mixed $value 110 | * @return void 111 | */ 112 | protected function fillAttribute(Site $record, string $attrKey, $value): void 113 | { 114 | $method = 'set' . Str::classify($attrKey); 115 | 116 | call_user_func([$record, $method], $value); 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel JSON API Demo 2 | 3 | This application demonstrates how to use the 4 | [cloudcreativity/laravel-json-api](https://github.com/cloudcreativity/laravel-json-api) 5 | package to create a [JSON API](http://jsonapi.org) compliant API. This is demonstrated using Eloquent models as 6 | the domain records that are serialized in the API, but the package is not Eloquent specific. 7 | 8 | ## Setup 9 | 10 | The application uses [Homestead](https://laravel.com/docs/homestead), so you'll need Vagrant installed on your 11 | local machine. 12 | 13 | Once you've cloned this repository, change into the project folder then: 14 | 15 | ``` bash 16 | composer install 17 | cp .env.example .env 18 | php vendor/bin/homestead make 19 | vagrant up 20 | ``` 21 | 22 | > Remember you'll need to add an entry for `homestead.app` in your `/etc/hosts` file. 23 | 24 | Once it is up and running, go to the following address in your browser to see the JSON endpoints: 25 | 26 | ``` 27 | http://homestead.app/api/v1/posts 28 | ``` 29 | 30 | To access the web interface: 31 | 32 | ``` 33 | http://homestead.app 34 | ``` 35 | 36 | > If you use the Vagrant hosts updater plugin, the hostname may be `demo-laravel-json-api` or similar. 37 | 38 | ## Authentication 39 | 40 | Any write requests require an authenticated user. We've installed 41 | [Laravel Passport](https://laravel.com/docs/passport) for API authentication. You will need to use 42 | [Personal Access Tokens](https://laravel.com/docs/passport#personal-access-tokens) and the Vagrant provisioning 43 | runs the Passport installation command. 44 | 45 | To create a token, go to the web interface and login (the username and password fields are completed with 46 | credentials that will sign you in successfully). You'll then see the Passport Person Access Token component 47 | which you can use to issue tokens. 48 | 49 | Once you have a token, send a request as follows, replacing the `` with your token. 50 | 51 | ```http 52 | POST http://homestead.app/api/v1/posts 53 | Accept: application/vnd.api+json 54 | Content-Type: application/vnd.api+json 55 | Authorization: Bearer 56 | 57 | { 58 | "data": { 59 | "type": "posts", 60 | "attributes": { 61 | "slug": "hello-world", 62 | "title": "Hello World", 63 | "content": "..." 64 | } 65 | } 66 | } 67 | ``` 68 | 69 | ## Eloquent vs Not-Eloquent 70 | 71 | This package can handle both Eloquent and non-Eloquent records. You get a lot more functionality out of the box if 72 | you are using Eloquent, but it's possible to integrate non-Eloquent records as needed. 73 | 74 | This demo includes the following JSON-API resources: 75 | 76 | | Resource | Record | Eloquent? | 77 | | --- | --- | --- | 78 | | comments | App\Comment | Yes | 79 | | posts | App\Post | Yes | 80 | | sites | App\Site | No | 81 | | tags | App\Tag | Yes | 82 | | users | App\User | Yes | 83 | 84 | ## Tests 85 | 86 | We're big on testing, and the `cloudcreativity/laravel-json-api` package comes with test helpers to make integration 87 | testing a JSON API a breeze. You can see this in action in the `tests/Integration` folder, where there's a test case 88 | for the `posts` resource. 89 | 90 | To run the tests: 91 | 92 | ```bash 93 | vendor/bin/phpunit 94 | ``` 95 | -------------------------------------------------------------------------------- /resources/views/auth/login.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
{{ __('Login') }}
9 | 10 |
11 |
12 | @csrf 13 | 14 |
15 | 16 | 17 |
18 | 19 | 20 | @if ($errors->has('email')) 21 | 22 | {{ $errors->first('email') }} 23 | 24 | @endif 25 |
26 |
27 | 28 |
29 | 30 | 31 |
32 | 33 | 34 | @if ($errors->has('password')) 35 | 36 | {{ $errors->first('password') }} 37 | 38 | @endif 39 |
40 |
41 | 42 |
43 |
44 |
45 | 48 |
49 |
50 |
51 | 52 |
53 |
54 | 57 | 58 | 59 | {{ __('Forgot Your Password?') }} 60 | 61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | @endsection 70 | -------------------------------------------------------------------------------- /resources/views/layouts/app.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | {{ config('app.name', 'Laravel JSON API') }} 12 | 13 | 14 | 15 | 16 | 17 |
18 | 63 | 64 |
65 | @yield('content') 66 |
67 |
68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /resources/views/auth/passwords/reset.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
{{ __('Reset Password') }}
9 | 10 |
11 |
12 | @csrf 13 | 14 | 15 | 16 |
17 | 18 | 19 |
20 | 21 | 22 | @if ($errors->has('email')) 23 | 24 | {{ $errors->first('email') }} 25 | 26 | @endif 27 |
28 |
29 | 30 |
31 | 32 | 33 |
34 | 35 | 36 | @if ($errors->has('password')) 37 | 38 | {{ $errors->first('password') }} 39 | 40 | @endif 41 |
42 |
43 | 44 |
45 | 46 |
47 | 48 | 49 | @if ($errors->has('password_confirmation')) 50 | 51 | {{ $errors->first('password_confirmation') }} 52 | 53 | @endif 54 |
55 |
56 | 57 |
58 |
59 | 62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | @endsection 71 | -------------------------------------------------------------------------------- /resources/assets/js/components/passport/AuthorizedClients.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 52 | 53 | 108 | -------------------------------------------------------------------------------- /resources/views/auth/register.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
{{ __('Register') }}
9 | 10 |
11 |
12 | @csrf 13 | 14 |
15 | 16 | 17 |
18 | 19 | 20 | @if ($errors->has('name')) 21 | 22 | {{ $errors->first('name') }} 23 | 24 | @endif 25 |
26 |
27 | 28 |
29 | 30 | 31 |
32 | 33 | 34 | @if ($errors->has('email')) 35 | 36 | {{ $errors->first('email') }} 37 | 38 | @endif 39 |
40 |
41 | 42 |
43 | 44 | 45 |
46 | 47 | 48 | @if ($errors->has('password')) 49 | 50 | {{ $errors->first('password') }} 51 | 52 | @endif 53 |
54 |
55 | 56 |
57 | 58 | 59 |
60 | 61 |
62 |
63 | 64 |
65 |
66 | 69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | @endsection 78 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => 'web', 18 | 'passwords' => 'users', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | here which uses session storage and the Eloquent user provider. 29 | | 30 | | All authentication drivers have a user provider. This defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | mechanisms used by this application to persist your user's data. 33 | | 34 | | Supported: "session", "token" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | 44 | 'api' => [ 45 | 'driver' => 'passport', 46 | 'provider' => 'users', 47 | ], 48 | ], 49 | 50 | /* 51 | |-------------------------------------------------------------------------- 52 | | User Providers 53 | |-------------------------------------------------------------------------- 54 | | 55 | | All authentication drivers have a user provider. This defines how the 56 | | users are actually retrieved out of your database or other storage 57 | | mechanisms used by this application to persist your user's data. 58 | | 59 | | If you have multiple user tables or models you may configure multiple 60 | | sources which represent each model / table. These sources may then 61 | | be assigned to any extra authentication guards you have defined. 62 | | 63 | | Supported: "database", "eloquent" 64 | | 65 | */ 66 | 67 | 'providers' => [ 68 | 'users' => [ 69 | 'driver' => 'eloquent', 70 | 'model' => App\User::class, 71 | ], 72 | 73 | // 'users' => [ 74 | // 'driver' => 'database', 75 | // 'table' => 'users', 76 | // ], 77 | ], 78 | 79 | /* 80 | |-------------------------------------------------------------------------- 81 | | Resetting Passwords 82 | |-------------------------------------------------------------------------- 83 | | 84 | | Here you may set the options for resetting passwords including the view 85 | | that is your password reset e-mail. You may also set the name of the 86 | | table that maintains all of the reset tokens for your application. 87 | | 88 | | You may specify multiple password reset configurations if you have more 89 | | than one user table or model in the application and you want to have 90 | | separate password reset settings based on the specific user types. 91 | | 92 | | The expire time is the number of minutes that the reset token should be 93 | | considered valid. This security feature keeps tokens short-lived so 94 | | they have less time to be guessed. You may change this as needed. 95 | | 96 | */ 97 | 98 | 'passwords' => [ 99 | 'users' => [ 100 | 'provider' => 'users', 101 | 'email' => 'auth.emails.password', 102 | 'table' => 'password_resets', 103 | 'expire' => 60, 104 | ], 105 | ], 106 | 107 | ]; 108 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_DRIVER', 'smtp'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | SMTP Host Address 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may provide the host address of the SMTP server used by your 27 | | applications. A default option is provided that is compatible with 28 | | the Mailgun mail service which will provide reliable deliveries. 29 | | 30 | */ 31 | 32 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | SMTP Host Port 37 | |-------------------------------------------------------------------------- 38 | | 39 | | This is the SMTP port used by your application to deliver e-mails to 40 | | users of the application. Like the host we have set this value to 41 | | stay compatible with the Mailgun e-mail application by default. 42 | | 43 | */ 44 | 45 | 'port' => env('MAIL_PORT', 587), 46 | 47 | /* 48 | |-------------------------------------------------------------------------- 49 | | Global "From" Address 50 | |-------------------------------------------------------------------------- 51 | | 52 | | You may wish for all e-mails sent by your application to be sent from 53 | | the same address. Here, you may specify a name and address that is 54 | | used globally for all e-mails that are sent by your application. 55 | | 56 | */ 57 | 58 | 'from' => ['address' => null, 'name' => null], 59 | 60 | /* 61 | |-------------------------------------------------------------------------- 62 | | E-Mail Encryption Protocol 63 | |-------------------------------------------------------------------------- 64 | | 65 | | Here you may specify the encryption protocol that should be used when 66 | | the application send e-mail messages. A sensible default using the 67 | | transport layer security protocol should provide great security. 68 | | 69 | */ 70 | 71 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 72 | 73 | /* 74 | |-------------------------------------------------------------------------- 75 | | SMTP Server Username 76 | |-------------------------------------------------------------------------- 77 | | 78 | | If your SMTP server requires a username for authentication, you should 79 | | set it here. This will get used to authenticate with your server on 80 | | connection. You may also set the "password" value below this one. 81 | | 82 | */ 83 | 84 | 'username' => env('MAIL_USERNAME'), 85 | 86 | /* 87 | |-------------------------------------------------------------------------- 88 | | SMTP Server Password 89 | |-------------------------------------------------------------------------- 90 | | 91 | | Here you may set the password required by your SMTP server to send out 92 | | messages from your application. This will be given to the server on 93 | | connection so that the application will be able to send messages. 94 | | 95 | */ 96 | 97 | 'password' => env('MAIL_PASSWORD'), 98 | 99 | /* 100 | |-------------------------------------------------------------------------- 101 | | Sendmail System Path 102 | |-------------------------------------------------------------------------- 103 | | 104 | | When using the "sendmail" driver to send e-mails, we will need to know 105 | | the path to where Sendmail lives on this server. A default path has 106 | | been provided here, which will work well on most of your systems. 107 | | 108 | */ 109 | 110 | 'sendmail' => '/usr/sbin/sendmail -bs', 111 | 112 | ]; 113 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | env('DB_CONNECTION', 'mysql'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Database Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here are each of the database connections setup for your application. 24 | | Of course, examples of configuring each database platform that is 25 | | supported by Laravel is shown below to make development simple. 26 | | 27 | | 28 | | All database work in Laravel is done through the PHP PDO facilities 29 | | so make sure you have the driver for your particular database of 30 | | choice installed on your machine before you begin development. 31 | | 32 | */ 33 | 34 | 'connections' => [ 35 | 36 | 'sqlite' => [ 37 | 'driver' => 'sqlite', 38 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 39 | 'prefix' => '', 40 | ], 41 | 42 | 'mysql' => [ 43 | 'driver' => 'mysql', 44 | 'host' => env('DB_HOST', '127.0.0.1'), 45 | 'port' => env('DB_PORT', '3306'), 46 | 'database' => env('DB_DATABASE', 'forge'), 47 | 'username' => env('DB_USERNAME', 'forge'), 48 | 'password' => env('DB_PASSWORD', ''), 49 | 'unix_socket' => env('DB_SOCKET', ''), 50 | 'charset' => 'utf8mb4', 51 | 'collation' => 'utf8mb4_unicode_ci', 52 | 'prefix' => '', 53 | 'strict' => true, 54 | 'engine' => null, 55 | ], 56 | 57 | 'pgsql' => [ 58 | 'driver' => 'pgsql', 59 | 'host' => env('DB_HOST', '127.0.0.1'), 60 | 'port' => env('DB_PORT', '5432'), 61 | 'database' => env('DB_DATABASE', 'forge'), 62 | 'username' => env('DB_USERNAME', 'forge'), 63 | 'password' => env('DB_PASSWORD', ''), 64 | 'charset' => 'utf8', 65 | 'prefix' => '', 66 | 'schema' => 'public', 67 | 'sslmode' => 'prefer', 68 | ], 69 | 70 | 'sqlsrv' => [ 71 | 'driver' => 'sqlsrv', 72 | 'host' => env('DB_HOST', 'localhost'), 73 | 'port' => env('DB_PORT', '1433'), 74 | 'database' => env('DB_DATABASE', 'forge'), 75 | 'username' => env('DB_USERNAME', 'forge'), 76 | 'password' => env('DB_PASSWORD', ''), 77 | 'charset' => 'utf8', 78 | 'prefix' => '', 79 | ], 80 | 81 | ], 82 | 83 | /* 84 | |-------------------------------------------------------------------------- 85 | | Migration Repository Table 86 | |-------------------------------------------------------------------------- 87 | | 88 | | This table keeps track of all the migrations that have already run for 89 | | your application. Using this information, we can determine which of 90 | | the migrations on disk haven't actually been run in the database. 91 | | 92 | */ 93 | 94 | 'migrations' => 'migrations', 95 | 96 | /* 97 | |-------------------------------------------------------------------------- 98 | | Redis Databases 99 | |-------------------------------------------------------------------------- 100 | | 101 | | Redis is an open source, fast, and advanced key-value store that also 102 | | provides a richer set of commands than a typical key-value systems 103 | | such as APC or Memcached. Laravel makes it easy to dig right in. 104 | | 105 | */ 106 | 107 | 'redis' => [ 108 | 109 | 'client' => 'predis', 110 | 111 | 'default' => [ 112 | 'host' => env('REDIS_HOST', '127.0.0.1'), 113 | 'password' => env('REDIS_PASSWORD', null), 114 | 'port' => env('REDIS_PORT', 6379), 115 | 'database' => 0, 116 | ], 117 | 118 | ], 119 | 120 | ]; 121 | -------------------------------------------------------------------------------- /tests/Feature/PostsTest.php: -------------------------------------------------------------------------------- 1 | create(); 25 | 26 | $this->doSearch([ 27 | 'page' => ['number' => 1, 'size' => 10], 28 | ])->assertSearchedMany(); 29 | } 30 | 31 | /** 32 | * Test that we can search posts for specific ids 33 | */ 34 | public function testSearchById() 35 | { 36 | $posts = factory(Post::class, 2)->create(); 37 | // this model should not be in the search results 38 | factory(Post::class, 2)->create(); 39 | 40 | $this->doSearchById($posts) 41 | ->assertSearchedIds($posts); 42 | } 43 | 44 | /** 45 | * Test the create resource route. 46 | */ 47 | public function testCreate() 48 | { 49 | /** @var Tag $tag */ 50 | $tag = factory(Tag::class)->create(); 51 | $post = factory(Post::class)->make(); 52 | 53 | $data = [ 54 | 'type' => 'posts', 55 | 'attributes' => [ 56 | 'title' => $post->title, 57 | 'slug' => $post->slug, 58 | 'content' => $post->content, 59 | // Dates must be passed in Atom format for JSON_API 60 | 'published-at' => $post->published_at->toAtomString(), 61 | ], 62 | 'relationships' => [ 63 | 'tags' => [ 64 | 'data' => [ 65 | [ 66 | 'type' => 'tags', 67 | 'id' => (string) $tag->getKey(), 68 | ], 69 | ], 70 | ], 71 | ], 72 | ]; 73 | 74 | Passport::actingAs($post->author); 75 | 76 | $id = $this 77 | ->doCreate($data, ['include' => 'author,tags']) 78 | ->assertCreatedWithId($data); 79 | 80 | $this->assertDatabaseHas('posts', [ 81 | 'id' => $id, 82 | 'title' => $post->title, 83 | 'slug' => $post->slug, 84 | 'content' => $post->content, 85 | 'published_at' => $post->published_at->toDateTimeString(), 86 | 'author_id' => $post->author_id, 87 | ]); 88 | 89 | $this->assertDatabaseHas('post_tag', [ 90 | 'post_id' => $id, 91 | 'tag_id' => $tag->getKey(), 92 | ]); 93 | } 94 | 95 | /** 96 | * Test the read resource route. 97 | */ 98 | public function testRead() 99 | { 100 | $post = factory(Post::class)->create(); 101 | $expected = $this->serialize($post); 102 | 103 | $this->doRead($post)->assertRead($expected); 104 | } 105 | 106 | /** 107 | * Test the update resource route. 108 | */ 109 | public function testUpdate() 110 | { 111 | $post = factory(Post::class)->create(); 112 | 113 | $data = [ 114 | 'type' => 'posts', 115 | 'id' => (string) $post->getRouteKey(), 116 | 'attributes' => [ 117 | 'slug' => 'posts-test', 118 | 'title' => 'Foo Bar Baz Bat', 119 | ], 120 | ]; 121 | 122 | Passport::actingAs($post->author); 123 | 124 | $this->doUpdate($data)->assertUpdated($data); 125 | 126 | $this->assertDatabaseHas('posts', [ 127 | 'id' => $post->getKey(), 128 | 'slug' => $data['attributes']['slug'], 129 | 'title' => $data['attributes']['title'], 130 | 'content' => $post->content, 131 | 'author_id' => $post->author_id, 132 | ]); 133 | } 134 | 135 | public function testUpdateForbidden() 136 | { 137 | $post = factory(Post::class)->create(); 138 | $user = factory(User::class)->create(); 139 | 140 | $data = [ 141 | 'type' => 'posts', 142 | 'id' => (string) $post->getRouteKey(), 143 | 'attributes' => [ 144 | 'slug' => 'posts-test', 145 | 'title' => 'Foo Bar Baz Bat', 146 | ], 147 | ]; 148 | 149 | Passport::actingAs($user); 150 | 151 | $this->doUpdate($data)->assertStatus(403); 152 | } 153 | 154 | /** 155 | * Test the delete resource route. 156 | */ 157 | public function testDelete() 158 | { 159 | $post = factory(Post::class)->create(); 160 | 161 | Passport::actingAs($post->author); 162 | 163 | $this->doDelete($post)->assertDeleted(); 164 | 165 | $this->assertDatabaseMissing('posts', ['id' => $post->getKey()]); 166 | } 167 | 168 | /** 169 | * @param Post $post 170 | * @return array 171 | */ 172 | private function serialize(Post $post) 173 | { 174 | $self = "http://localhost/api/v1/posts/{$post->getKey()}"; 175 | 176 | return [ 177 | 'type' => 'posts', 178 | 'id' => (string) $post->getRouteKey(), 179 | 'attributes' => [ 180 | 'title' => $post->title, 181 | 'slug' => $post->slug, 182 | 'content' => $post->content, 183 | 'published-at' => $post->published_at->toAtomString(), 184 | ], 185 | 'relationships' => [ 186 | 'author' => [ 187 | 'links' => [ 188 | 'self' => "{$self}/relationships/author", 189 | 'related' => "{$self}/author", 190 | ], 191 | ], 192 | 'comments' => [ 193 | 'links' => [ 194 | 'self' => "{$self}/relationships/comments", 195 | 'related' => "{$self}/comments", 196 | ], 197 | ], 198 | 'tags' => [ 199 | 'links' => [ 200 | 'self' => "{$self}/relationships/tags", 201 | 'related' => "{$self}/tags", 202 | ], 203 | ], 204 | ], 205 | 'links' => [ 206 | 'self' => $self, 207 | ], 208 | ]; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /resources/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | 'The :attribute must be accepted.', 17 | 'active_url' => 'The :attribute is not a valid URL.', 18 | 'after' => 'The :attribute must be a date after :date.', 19 | 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', 20 | 'alpha' => 'The :attribute may only contain letters.', 21 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', 22 | 'alpha_num' => 'The :attribute may only contain letters and numbers.', 23 | 'array' => 'The :attribute must be an array.', 24 | 'before' => 'The :attribute must be a date before :date.', 25 | 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', 26 | 'between' => [ 27 | 'numeric' => 'The :attribute must be between :min and :max.', 28 | 'file' => 'The :attribute must be between :min and :max kilobytes.', 29 | 'string' => 'The :attribute must be between :min and :max characters.', 30 | 'array' => 'The :attribute must have between :min and :max items.', 31 | ], 32 | 'boolean' => 'The :attribute field must be true or false.', 33 | 'confirmed' => 'The :attribute confirmation does not match.', 34 | 'date' => 'The :attribute is not a valid date.', 35 | 'date_format' => 'The :attribute does not match the format :format.', 36 | 'different' => 'The :attribute and :other must be different.', 37 | 'digits' => 'The :attribute must be :digits digits.', 38 | 'digits_between' => 'The :attribute must be between :min and :max digits.', 39 | 'dimensions' => 'The :attribute has invalid image dimensions.', 40 | 'distinct' => 'The :attribute field has a duplicate value.', 41 | 'email' => 'The :attribute must be a valid email address.', 42 | 'exists' => 'The selected :attribute is invalid.', 43 | 'file' => 'The :attribute must be a file.', 44 | 'filled' => 'The :attribute field must have a value.', 45 | 'image' => 'The :attribute must be an image.', 46 | 'in' => 'The selected :attribute is invalid.', 47 | 'in_array' => 'The :attribute field does not exist in :other.', 48 | 'integer' => 'The :attribute must be an integer.', 49 | 'ip' => 'The :attribute must be a valid IP address.', 50 | 'ipv4' => 'The :attribute must be a valid IPv4 address.', 51 | 'ipv6' => 'The :attribute must be a valid IPv6 address.', 52 | 'json' => 'The :attribute must be a valid JSON string.', 53 | 'max' => [ 54 | 'numeric' => 'The :attribute may not be greater than :max.', 55 | 'file' => 'The :attribute may not be greater than :max kilobytes.', 56 | 'string' => 'The :attribute may not be greater than :max characters.', 57 | 'array' => 'The :attribute may not have more than :max items.', 58 | ], 59 | 'mimes' => 'The :attribute must be a file of type: :values.', 60 | 'mimetypes' => 'The :attribute must be a file of type: :values.', 61 | 'min' => [ 62 | 'numeric' => 'The :attribute must be at least :min.', 63 | 'file' => 'The :attribute must be at least :min kilobytes.', 64 | 'string' => 'The :attribute must be at least :min characters.', 65 | 'array' => 'The :attribute must have at least :min items.', 66 | ], 67 | 'not_in' => 'The selected :attribute is invalid.', 68 | 'numeric' => 'The :attribute must be a number.', 69 | 'present' => 'The :attribute field must be present.', 70 | 'regex' => 'The :attribute format is invalid.', 71 | 'required' => 'The :attribute field is required.', 72 | 'required_if' => 'The :attribute field is required when :other is :value.', 73 | 'required_unless' => 'The :attribute field is required unless :other is in :values.', 74 | 'required_with' => 'The :attribute field is required when :values is present.', 75 | 'required_with_all' => 'The :attribute field is required when :values is present.', 76 | 'required_without' => 'The :attribute field is required when :values is not present.', 77 | 'required_without_all' => 'The :attribute field is required when none of :values are present.', 78 | 'same' => 'The :attribute and :other must match.', 79 | 'size' => [ 80 | 'numeric' => 'The :attribute must be :size.', 81 | 'file' => 'The :attribute must be :size kilobytes.', 82 | 'string' => 'The :attribute must be :size characters.', 83 | 'array' => 'The :attribute must contain :size items.', 84 | ], 85 | 'string' => 'The :attribute must be a string.', 86 | 'timezone' => 'The :attribute must be a valid zone.', 87 | 'unique' => 'The :attribute has already been taken.', 88 | 'uploaded' => 'The :attribute failed to upload.', 89 | 'url' => 'The :attribute format is invalid.', 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Custom Validation Language Lines 94 | |-------------------------------------------------------------------------- 95 | | 96 | | Here you may specify custom validation messages for attributes using the 97 | | convention "attribute.rule" to name the lines. This makes it quick to 98 | | specify a specific custom language line for a given attribute rule. 99 | | 100 | */ 101 | 102 | 'custom' => [ 103 | 'attribute-name' => [ 104 | 'rule-name' => 'custom-message', 105 | ], 106 | ], 107 | 108 | /* 109 | |-------------------------------------------------------------------------- 110 | | Custom Validation Attributes 111 | |-------------------------------------------------------------------------- 112 | | 113 | | The following language lines are used to swap attribute place-holders 114 | | with something more reader friendly such as E-Mail Address instead 115 | | of "email". This simply helps us make messages a little cleaner. 116 | | 117 | */ 118 | 119 | 'attributes' => [], 120 | 121 | ]; 122 | -------------------------------------------------------------------------------- /config/json-api-v1.php: -------------------------------------------------------------------------------- 1 | null, 25 | 'by-resource' => true, 26 | 27 | /* 28 | |-------------------------------------------------------------------------- 29 | | Resources 30 | |-------------------------------------------------------------------------- 31 | | 32 | | Here you map the list of JSON API resources in your API to the actual 33 | | record (model/entity) classes they relate to. 34 | | 35 | | For example, if you had a `posts` JSON API resource, that related to 36 | | an Eloquent model `App\Post`, your mapping would be: 37 | | 38 | | `'posts' => App\Post::class` 39 | */ 40 | 'resources' => [ 41 | 'comments' => \App\Comment::class, 42 | 'posts' => \App\Post::class, 43 | 'sites' => \App\Site::class, 44 | 'tags' => \App\Tag::class, 45 | 'users' => \App\User::class, 46 | ], 47 | 48 | /* 49 | |-------------------------------------------------------------------------- 50 | | Eloquent 51 | |-------------------------------------------------------------------------- 52 | | 53 | | Whether your JSON API resources predominantly relate to Eloquent models. 54 | | This is used by the package's generators. 55 | | 56 | | You can override the setting here when running a generator. If the 57 | | setting here is `true` running a generator with `--no-eloquent` will 58 | | override it; if the setting is `false`, then `--eloquent` is the override. 59 | | 60 | */ 61 | 'use-eloquent' => true, 62 | 63 | /* 64 | |-------------------------------------------------------------------------- 65 | | URL 66 | |-------------------------------------------------------------------------- 67 | | 68 | | The API's url, made up of a host, URL namespace and route name prefix. 69 | | 70 | | If a JSON API is handling an inbound request, the host will always be 71 | | detected from the inbound HTTP request. In other circumstances 72 | | (e.g. broadcasting), the host will be taken from the setting here. 73 | | If it is `null`, the `app.url` config setting is used as the default. 74 | | 75 | | The name setting is the prefix for route names within this API. 76 | | 77 | */ 78 | 'url' => [ 79 | 'host' => null, 80 | 'namespace' => '/api/v1', 81 | 'name' => 'api:v1:', 82 | ], 83 | 84 | /* 85 | |-------------------------------------------------------------------------- 86 | | Supported JSON API Extensions 87 | |-------------------------------------------------------------------------- 88 | | 89 | | Refer to the JSON API spec for information on supported extensions. 90 | | 91 | */ 92 | 'supported-ext' => null, 93 | 94 | /* 95 | |-------------------------------------------------------------------------- 96 | | Encoding Media Types 97 | |-------------------------------------------------------------------------- 98 | | 99 | | This defines the JSON API encoding used for particular media 100 | | types supported by your API. This array can contain either 101 | | media types as values, or can be keyed by a media type with the value 102 | | being the options that are passed to the `json_encode` method. 103 | | 104 | | These values are also used for Content Negotiation. If a client requests 105 | | via the HTTP Accept header a media type that is not listed here, 106 | | a 406 Not Acceptable response will be sent. 107 | | 108 | | If you want to support media types that do not return responses with JSON 109 | | API encoded data, you can do this at runtime. Refer to the 110 | | Content Negotiation chapter in the docs for details. 111 | | 112 | */ 113 | 'encoding' => [ 114 | 'application/vnd.api+json', 115 | ], 116 | 117 | /* 118 | |-------------------------------------------------------------------------- 119 | | Decoding Media Types 120 | |-------------------------------------------------------------------------- 121 | | 122 | | This defines the media types that your API can receive from clients. 123 | | This array is keyed by expected media types, with the value being the 124 | | service binding that decodes the media type. 125 | | 126 | | These values are also used for Content Negotiation. If a client sends 127 | | a content type not listed here, it will receive a 128 | | 415 Unsupported Media Type response. 129 | | 130 | | Decoders can also be calculated at runtime, and/or you can add support 131 | | for media types for specific resources or requests. Refer to the 132 | | Content Negotiation chapter in the docs for details. 133 | | 134 | */ 135 | 'decoding' => [ 136 | 'application/vnd.api+json', 137 | ], 138 | 139 | /* 140 | |-------------------------------------------------------------------------- 141 | | Providers 142 | |-------------------------------------------------------------------------- 143 | | 144 | | Providers allow vendor packages to include resources in your API. E.g. 145 | | a Shopping Cart vendor package might define the `orders` and `payments` 146 | | JSON API resources. 147 | | 148 | | A package author will define a provider class in their package that you 149 | | can add here. E.g. for our shopping cart example, the provider could be 150 | | `Vendor\ShoppingCart\JsonApi\ResourceProvider`. 151 | | 152 | */ 153 | 'providers' => [], 154 | 155 | /* 156 | |-------------------------------------------------------------------------- 157 | | Errors 158 | |-------------------------------------------------------------------------- 159 | | 160 | | This is an array of JSON API errors that can be returned by the API. 161 | | The value here is an array of errors specific to this API, with string 162 | | array keys that are the references used to create those errors. 163 | | 164 | | Errors contained here will be merged on top of the default errors 165 | | supplied by this package (merging is not recursive). This means if you 166 | | need to override any of the default errors, you can include an error here 167 | | with the same key as the default error you want to override. Default 168 | | errors can be found in the package's 'config/json-api-errors.php' file. 169 | */ 170 | 'errors' => [], 171 | 172 | ]; 173 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'file'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Session Lifetime 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may specify the number of minutes that you wish the session 27 | | to be allowed to remain idle before it expires. If you want them 28 | | to immediately expire on the browser closing, set that option. 29 | | 30 | */ 31 | 32 | 'lifetime' => 120, 33 | 34 | 'expire_on_close' => false, 35 | 36 | /* 37 | |-------------------------------------------------------------------------- 38 | | Session Encryption 39 | |-------------------------------------------------------------------------- 40 | | 41 | | This option allows you to easily specify that all of your session data 42 | | should be encrypted before it is stored. All encryption will be run 43 | | automatically by Laravel and you can use the Session like normal. 44 | | 45 | */ 46 | 47 | 'encrypt' => false, 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | Session File Location 52 | |-------------------------------------------------------------------------- 53 | | 54 | | When using the native session driver, we need a location where session 55 | | files may be stored. A default has been set for you but a different 56 | | location may be specified. This is only needed for file sessions. 57 | | 58 | */ 59 | 60 | 'files' => storage_path('framework/sessions'), 61 | 62 | /* 63 | |-------------------------------------------------------------------------- 64 | | Session Database Connection 65 | |-------------------------------------------------------------------------- 66 | | 67 | | When using the "database" or "redis" session drivers, you may specify a 68 | | connection that should be used to manage these sessions. This should 69 | | correspond to a connection in your database configuration options. 70 | | 71 | */ 72 | 73 | 'connection' => null, 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Session Database Table 78 | |-------------------------------------------------------------------------- 79 | | 80 | | When using the "database" session driver, you may specify the table we 81 | | should use to manage the sessions. Of course, a sensible default is 82 | | provided for you; however, you are free to change this as needed. 83 | | 84 | */ 85 | 86 | 'table' => 'sessions', 87 | 88 | /* 89 | |-------------------------------------------------------------------------- 90 | | Session Cache Store 91 | |-------------------------------------------------------------------------- 92 | | 93 | | When using the "apc" or "memcached" session drivers, you may specify a 94 | | cache store that should be used for these sessions. This value must 95 | | correspond with one of the application's configured cache stores. 96 | | 97 | */ 98 | 99 | 'store' => null, 100 | 101 | /* 102 | |-------------------------------------------------------------------------- 103 | | Session Sweeping Lottery 104 | |-------------------------------------------------------------------------- 105 | | 106 | | Some session drivers must manually sweep their storage location to get 107 | | rid of old sessions from storage. Here are the chances that it will 108 | | happen on a given request. By default, the odds are 2 out of 100. 109 | | 110 | */ 111 | 112 | 'lottery' => [2, 100], 113 | 114 | /* 115 | |-------------------------------------------------------------------------- 116 | | Session Cookie Name 117 | |-------------------------------------------------------------------------- 118 | | 119 | | Here you may change the name of the cookie used to identify a session 120 | | instance by ID. The name specified here will get used every time a 121 | | new session cookie is created by the framework for every driver. 122 | | 123 | */ 124 | 125 | 'cookie' => env( 126 | 'SESSION_COOKIE', 127 | str_slug(env('APP_NAME', 'laravel'), '_').'_session' 128 | ), 129 | 130 | /* 131 | |-------------------------------------------------------------------------- 132 | | Session Cookie Path 133 | |-------------------------------------------------------------------------- 134 | | 135 | | The session cookie path determines the path for which the cookie will 136 | | be regarded as available. Typically, this will be the root path of 137 | | your application but you are free to change this when necessary. 138 | | 139 | */ 140 | 141 | 'path' => '/', 142 | 143 | /* 144 | |-------------------------------------------------------------------------- 145 | | Session Cookie Domain 146 | |-------------------------------------------------------------------------- 147 | | 148 | | Here you may change the domain of the cookie used to identify a session 149 | | in your application. This will determine which domains the cookie is 150 | | available to in your application. A sensible default has been set. 151 | | 152 | */ 153 | 154 | 'domain' => env('SESSION_DOMAIN', null), 155 | 156 | /* 157 | |-------------------------------------------------------------------------- 158 | | HTTPS Only Cookies 159 | |-------------------------------------------------------------------------- 160 | | 161 | | By setting this option to true, session cookies will only be sent back 162 | | to the server if the browser has a HTTPS connection. This will keep 163 | | the cookie from being sent to you if it can not be done securely. 164 | | 165 | */ 166 | 167 | 'secure' => env('SESSION_SECURE_COOKIE', false), 168 | 169 | /* 170 | |-------------------------------------------------------------------------- 171 | | HTTP Access Only 172 | |-------------------------------------------------------------------------- 173 | | 174 | | Setting this value to true will prevent JavaScript from accessing the 175 | | value of the cookie and the cookie will only be accessible through 176 | | the HTTP protocol. You are free to modify this option if needed. 177 | | 178 | */ 179 | 180 | 'http_only' => true, 181 | 182 | /* 183 | |-------------------------------------------------------------------------- 184 | | Same-Site Cookies 185 | |-------------------------------------------------------------------------- 186 | | 187 | | This option determines how your cookies behave when cross-site requests 188 | | take place, and can be used to mitigate CSRF attacks. By default, we 189 | | do not enable this as other CSRF protection services are in place. 190 | | 191 | | Supported: "lax", "strict" 192 | | 193 | */ 194 | 195 | 'same_site' => null, 196 | 197 | ]; 198 | -------------------------------------------------------------------------------- /config/app.php: -------------------------------------------------------------------------------- 1 | 'Laravel JSON API', 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Application Environment 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This value determines the "environment" your application is currently 24 | | running in. This may determine how you prefer to configure various 25 | | services your application utilizes. Set this in your ".env" file. 26 | | 27 | */ 28 | 29 | 'env' => env('APP_ENV', 'production'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Application Debug Mode 34 | |-------------------------------------------------------------------------- 35 | | 36 | | When your application is in debug mode, detailed error messages with 37 | | stack traces will be shown on every error that occurs within your 38 | | application. If disabled, a simple generic error page is shown. 39 | | 40 | */ 41 | 42 | 'debug' => env('APP_DEBUG', false), 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Application URL 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This URL is used by the console to properly generate URLs when using 50 | | the Artisan command line tool. You should set this to the root of 51 | | your application so that it is used when running Artisan tasks. 52 | | 53 | */ 54 | 55 | 'url' => env('APP_URL', 'http://localhost'), 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Application Timezone 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Here you may specify the default timezone for your application, which 63 | | will be used by the PHP date and date-time functions. We have gone 64 | | ahead and set this to a sensible default for you out of the box. 65 | | 66 | */ 67 | 68 | 'timezone' => 'UTC', 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Application Locale Configuration 73 | |-------------------------------------------------------------------------- 74 | | 75 | | The application locale determines the default locale that will be used 76 | | by the translation service provider. You are free to set this value 77 | | to any of the locales which will be supported by the application. 78 | | 79 | */ 80 | 81 | 'locale' => 'en', 82 | 83 | /* 84 | |-------------------------------------------------------------------------- 85 | | Application Fallback Locale 86 | |-------------------------------------------------------------------------- 87 | | 88 | | The fallback locale determines the locale to use when the current one 89 | | is not available. You may change the value to correspond to any of 90 | | the language folders that are provided through your application. 91 | | 92 | */ 93 | 94 | 'fallback_locale' => 'en', 95 | 96 | /* 97 | |-------------------------------------------------------------------------- 98 | | Encryption Key 99 | |-------------------------------------------------------------------------- 100 | | 101 | | This key is used by the Illuminate encrypter service and should be set 102 | | to a random, 32 character string, otherwise these encrypted strings 103 | | will not be safe. Please do this before deploying an application! 104 | | 105 | */ 106 | 107 | 'key' => env('APP_KEY'), 108 | 109 | 'cipher' => 'AES-256-CBC', 110 | 111 | /* 112 | |-------------------------------------------------------------------------- 113 | | Logging Configuration 114 | |-------------------------------------------------------------------------- 115 | | 116 | | Here you may configure the log settings for your application. Out of 117 | | the box, Laravel uses the Monolog PHP logging library. This gives 118 | | you a variety of powerful log handlers / formatters to utilize. 119 | | 120 | | Available Settings: "single", "daily", "syslog", "errorlog" 121 | | 122 | */ 123 | 124 | 'log' => env('APP_LOG', 'single'), 125 | 126 | 'log_level' => env('APP_LOG_LEVEL', 'debug'), 127 | 128 | /* 129 | |-------------------------------------------------------------------------- 130 | | Autoloaded Service Providers 131 | |-------------------------------------------------------------------------- 132 | | 133 | | The service providers listed here will be automatically loaded on the 134 | | request to your application. Feel free to add your own services to 135 | | this array to grant expanded functionality to your applications. 136 | | 137 | */ 138 | 139 | 'providers' => [ 140 | 141 | /* 142 | * Laravel Framework Service Providers... 143 | */ 144 | Illuminate\Auth\AuthServiceProvider::class, 145 | Illuminate\Broadcasting\BroadcastServiceProvider::class, 146 | Illuminate\Bus\BusServiceProvider::class, 147 | Illuminate\Cache\CacheServiceProvider::class, 148 | Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, 149 | Illuminate\Cookie\CookieServiceProvider::class, 150 | Illuminate\Database\DatabaseServiceProvider::class, 151 | Illuminate\Encryption\EncryptionServiceProvider::class, 152 | Illuminate\Filesystem\FilesystemServiceProvider::class, 153 | Illuminate\Foundation\Providers\FoundationServiceProvider::class, 154 | Illuminate\Hashing\HashServiceProvider::class, 155 | Illuminate\Mail\MailServiceProvider::class, 156 | Illuminate\Notifications\NotificationServiceProvider::class, 157 | Illuminate\Pagination\PaginationServiceProvider::class, 158 | Illuminate\Pipeline\PipelineServiceProvider::class, 159 | Illuminate\Queue\QueueServiceProvider::class, 160 | Illuminate\Redis\RedisServiceProvider::class, 161 | Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, 162 | Illuminate\Session\SessionServiceProvider::class, 163 | Illuminate\Translation\TranslationServiceProvider::class, 164 | Illuminate\Validation\ValidationServiceProvider::class, 165 | Illuminate\View\ViewServiceProvider::class, 166 | 167 | /* 168 | * Package Service Providers... 169 | */ 170 | 171 | /* 172 | * Application Service Providers... 173 | */ 174 | App\Providers\AppServiceProvider::class, 175 | App\Providers\AuthServiceProvider::class, 176 | // App\Providers\BroadcastServiceProvider::class, 177 | App\Providers\EventServiceProvider::class, 178 | App\Providers\RouteServiceProvider::class, 179 | 180 | ], 181 | 182 | /* 183 | |-------------------------------------------------------------------------- 184 | | Class Aliases 185 | |-------------------------------------------------------------------------- 186 | | 187 | | This array of class aliases will be registered when this application 188 | | is started. However, feel free to register as many as you wish as 189 | | the aliases are "lazy" loaded so they don't hinder performance. 190 | | 191 | */ 192 | 193 | 'aliases' => [ 194 | 195 | 'App' => Illuminate\Support\Facades\App::class, 196 | 'Artisan' => Illuminate\Support\Facades\Artisan::class, 197 | 'Auth' => Illuminate\Support\Facades\Auth::class, 198 | 'Blade' => Illuminate\Support\Facades\Blade::class, 199 | 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, 200 | 'Bus' => Illuminate\Support\Facades\Bus::class, 201 | 'Cache' => Illuminate\Support\Facades\Cache::class, 202 | 'Config' => Illuminate\Support\Facades\Config::class, 203 | 'Cookie' => Illuminate\Support\Facades\Cookie::class, 204 | 'Crypt' => Illuminate\Support\Facades\Crypt::class, 205 | 'DB' => Illuminate\Support\Facades\DB::class, 206 | 'Eloquent' => Illuminate\Database\Eloquent\Model::class, 207 | 'Event' => Illuminate\Support\Facades\Event::class, 208 | 'File' => Illuminate\Support\Facades\File::class, 209 | 'Gate' => Illuminate\Support\Facades\Gate::class, 210 | 'Hash' => Illuminate\Support\Facades\Hash::class, 211 | 'Lang' => Illuminate\Support\Facades\Lang::class, 212 | 'Log' => Illuminate\Support\Facades\Log::class, 213 | 'Mail' => Illuminate\Support\Facades\Mail::class, 214 | 'Notification' => Illuminate\Support\Facades\Notification::class, 215 | 'Password' => Illuminate\Support\Facades\Password::class, 216 | 'Queue' => Illuminate\Support\Facades\Queue::class, 217 | 'Redirect' => Illuminate\Support\Facades\Redirect::class, 218 | 'Redis' => Illuminate\Support\Facades\Redis::class, 219 | 'Request' => Illuminate\Support\Facades\Request::class, 220 | 'Response' => Illuminate\Support\Facades\Response::class, 221 | 'Route' => Illuminate\Support\Facades\Route::class, 222 | 'Schema' => Illuminate\Support\Facades\Schema::class, 223 | 'Session' => Illuminate\Support\Facades\Session::class, 224 | 'Storage' => Illuminate\Support\Facades\Storage::class, 225 | 'URL' => Illuminate\Support\Facades\URL::class, 226 | 'Validator' => Illuminate\Support\Facades\Validator::class, 227 | 'View' => Illuminate\Support\Facades\View::class, 228 | 229 | ], 230 | 231 | ]; 232 | -------------------------------------------------------------------------------- /resources/assets/js/components/passport/PersonalAccessTokens.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 156 | 157 | 299 | -------------------------------------------------------------------------------- /resources/assets/js/components/passport/Clients.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 212 | 213 | 351 | --------------------------------------------------------------------------------