├── .editorconfig
├── .env.example
├── .gitignore
├── .htaccess
├── README.MD
├── README2.MD
├── app
├── console
│ └── ExampleCommand.php
├── controllers
│ └── Controller.php
├── database
│ ├── .gitignore
│ ├── factories
│ │ ├── Factory.php
│ │ └── UserFactory.php
│ ├── migrations
│ │ ├── 2019_11_18_133625_create_users.php
│ │ └── 2019_11_18_155705_create_password_resets.php
│ ├── schema
│ │ └── users.json
│ └── seeds
│ │ ├── DatabaseSeeder.php
│ │ └── UsersSeeder.php
├── helpers
│ └── .gitkeep
├── models
│ ├── Model.php
│ └── User.php
├── routes
│ ├── _app.php
│ └── index.php
└── views
│ └── .gitkeep
├── composer.json
├── config
├── app.php
├── auth.php
├── cors.php
├── csrf.php
├── database.php
├── paths.php
└── view.php
├── index.php
├── leaf
├── lib
└── .gitkeep
├── public
├── .htaccess
├── assets
│ └── .gitkeep
├── favicon.ico
├── index.php
├── robots.txt
└── web.config
└── storage
├── app
└── public
│ └── .gitignore
├── framework
└── views
│ └── .gitignore
└── logs
└── .gitignore
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | insert_final_newline = true
7 | indent_style = space
8 | indent_size = 4
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
14 | [*.{yml,yaml}]
15 | indent_size = 2
16 |
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | APP_NAME=LEAF_MVC
2 | APP_ENV=local
3 | APP_KEY=base64:AUAyDriQD1kFdIAPIbwTHlnCm2pYn+qxDBa55SFwB9PUzg=
4 | APP_DOWN=false
5 | APP_DEBUG=true
6 | APP_PORT=5500
7 | APP_URL=http://localhost:5500/
8 |
9 | DB_CONNECTION=mysql
10 | DB_HOST=127.0.0.1
11 | DB_PORT=3306
12 | DB_DATABASE=LEAF_DB_NAME
13 | DB_USERNAME=LEAF_DB_USERNAME
14 | DB_PASSWORD=
15 | DB_CHARSET=utf8
16 | DB_COLLATION=utf8_unicode_ci
17 | # DB_COLLATION=utf8_general_ci
18 |
19 | MAIL_DRIVER=smtp
20 | MAIL_HOST=smtp.mailtrap.io
21 | MAIL_PORT=2525
22 | MAIL_DEBUG=SERVER
23 | MAIL_USERNAME=null
24 | MAIL_PASSWORD=null
25 | MAIL_ENCRYPTION=null
26 |
27 | PROD_SERVER=hello
28 | PROD_PORT=22
29 | PROD_USER=leaf
30 |
31 | SERVER_NAME=LEAF_SERVER
32 | SERVER_PORT=5500
33 | SERVER_USER=
34 | SERVER_PASSWORD=
35 |
36 | APPLICATION_DIR=leaf
37 | APPLICATION_PATH=leaf
38 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .env
2 | .env.backup
3 | .env.production
4 | build
5 | dist
6 | compiled
7 | .idea
8 | hot
9 | vendor
10 | node_modules
11 | npm-debug.log
12 | yarn-error.log
13 |
--------------------------------------------------------------------------------
/.htaccess:
--------------------------------------------------------------------------------
1 |
2 |
3 | Options -MultiViews -Indexes
4 |
5 |
6 | RewriteEngine On
7 |
8 | # prevent http access to .env
9 |
10 | Order Allow,Deny
11 | Deny from all
12 |
13 |
14 | # Handle Authorization Header
15 | RewriteCond %{HTTP:Authorization} .
16 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
17 |
18 | # Redirect Trailing Slashes If Not A Folder...
19 | RewriteCond %{REQUEST_FILENAME} !-d
20 | RewriteCond %{REQUEST_URI} (.+)/$
21 | RewriteRule ^ %1 [L,R=301]
22 |
23 | # Handle Front Controller...
24 | RewriteCond %{REQUEST_FILENAME} !-d
25 | RewriteCond %{REQUEST_FILENAME} !-f
26 | RewriteRule ^ index.php [L]
27 |
28 |
--------------------------------------------------------------------------------
/README.MD:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | # Leaf API
8 |
9 | [](https://packagist.org/packages/leafs/api)
10 | [](https://packagist.org/packages/leafs/api)
11 | [](https://packagist.org/packages/leafs/api)
12 |
13 | Leaf API has been merged into Leaf MVC, so we will be archiving this repo. Leaf MVC provides all the same functionality that was present in this repo and even offers the same structure and files if installed through the Leaf CLI. Once again, this is not us abandoning Leaf API, we are simply merging it with Leaf MVC so we can better utilize our scarce resources.
14 |
15 | If you started a project before the merge, don't worry. Not much has changed, just remember to keep your dependencies up to date and you'll be just fine.
16 |
17 | ## 🤩 Sponsoring Leaf
18 |
19 | Your cash contributions go a long way to help us make Leaf even better for you. You can sponsor Leaf and any of our packages on [open collective](https://opencollective.com/leaf) or check the [contribution page](https://leafphp.dev/support/) for a list of ways to contribute.
20 |
21 | We will furthermore like to thank our existing supporters, we love you all ❤️
22 |
23 | ## 💬 Stay In Touch
24 |
25 | - [Twitter](https://twitter.com/leafphp)
26 | - [Join the forum](https://github.com/leafsphp/leaf/discussions/37)
27 | - [Chat on discord](https://discord.com/invite/Pkrm9NJPE3)
28 |
--------------------------------------------------------------------------------
/README2.MD:
--------------------------------------------------------------------------------
1 | # README
2 |
3 | This README would normally document whatever steps are necessary to get the application up and running.
4 |
5 | Things you may want to cover:
6 |
7 | ## App Info
8 |
9 | ## Installation
10 |
11 | ## System dependencies
12 |
13 | ## Configuration
14 |
15 | ## Database creation
16 |
17 | ## Database initialization
18 |
19 | ## Deployment instructions
20 |
--------------------------------------------------------------------------------
/app/console/ExampleCommand.php:
--------------------------------------------------------------------------------
1 | setArgument('argument', 'optional', 'argument description')
17 | ->setOption('option', 'o', 'required', 'option description');
18 | }
19 |
20 | protected function handle()
21 | {
22 | $this->comment(
23 | "example command's output {$this->argument('argument')} {$this->option('option')}"
24 | );
25 |
26 | return 0;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/controllers/Controller.php:
--------------------------------------------------------------------------------
1 | faker and $this->str respectively
18 | */
19 | class Factory extends Base
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/app/database/factories/UserFactory.php:
--------------------------------------------------------------------------------
1 | strtolower($this->faker->firstName),
19 | 'fullname' => $this->faker->name,
20 | 'email' => $this->faker->unique()->safeEmail,
21 | 'email_verified_at' => tick()->now(),
22 | 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
23 | 'remember_token' => $this->str::random(10),
24 | ];
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/database/migrations/2019_11_18_133625_create_users.php:
--------------------------------------------------------------------------------
1 | hasTable("users")):
16 | // static::$capsule::schema()->create("users", function (Blueprint $table) {
17 | // $table->increments('id');
18 | // $table->string('username');
19 | // $table->string('fullname');
20 | // $table->string('email')->unique();
21 | // $table->timestamp('email_verified_at')->nullable();
22 | // $table->string('password');
23 | // $table->rememberToken();
24 | // $table->timestamps();
25 | // });
26 | // endif;
27 |
28 | /**
29 | * Leaf Schema allows you to build migrations
30 | * from a JSON representation of your database
31 | *
32 | * Check app/database/schema/users.json for an example
33 | *
34 | * Docs @ https://leafphp.dev/docs/mvc/schema.html
35 | */
36 | // you can now build your migrations with schemas
37 | Schema::build('users');
38 | }
39 |
40 | /**
41 | * Reverse the migrations.
42 | * @return void
43 | */
44 | public function down()
45 | {
46 | static::$capsule::schema()->dropIfExists('users');
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/database/migrations/2019_11_18_155705_create_password_resets.php:
--------------------------------------------------------------------------------
1 | hasTable('password_resets')) :
15 | static::$capsule::schema()->create('password_resets', function (Blueprint $table) {
16 | $table->string('email')->index();
17 | $table->string('token');
18 | $table->timestamp('created_at')->nullable();
19 | });
20 | endif;
21 | }
22 |
23 | /**
24 | * Reverse the migrations.
25 | * @return void
26 | */
27 | public function down()
28 | {
29 | static::$capsule::schema()->dropIfExists('password_resets');
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/database/schema/users.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": 1,
3 | "username?": "mychi.darko",
4 | "fullname": "Mychi Darko",
5 | "email": "mickdd22@gmail.com",
6 | "email_verified_at?": "2021-07-23T16:18:35.947712157Z",
7 | "password": "poekojdenwjwiojweojojweoijoewoj",
8 | "remember_token?": "deiwoj",
9 | "timestamps": ""
10 | }
11 |
--------------------------------------------------------------------------------
/app/database/seeds/DatabaseSeeder.php:
--------------------------------------------------------------------------------
1 | username = 'mychi';
21 | // $user->fullname = 'Mychi Darko';
22 | // $user->email = 'mychi@leafphp.dev';
23 | // $user->password = \Leaf\Password::hash('password');
24 | // $user->save();
25 |
26 | // You can also use factories like this 👇
27 | (new UserFactory)->create(5)->save();
28 |
29 | // even better, you can use them together :-)
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/helpers/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsphp/leafAPI/7a9e49275ca2672b6623b833e5f1593e5afd1b6f/app/helpers/.gitkeep
--------------------------------------------------------------------------------
/app/models/Model.php:
--------------------------------------------------------------------------------
1 | 'datetime',
35 | ];
36 | }
37 |
--------------------------------------------------------------------------------
/app/routes/_app.php:
--------------------------------------------------------------------------------
1 | get('/', function () {
4 | response()->json(['message' => 'Congrats!! You\'re on Leaf API']);
5 | });
6 |
--------------------------------------------------------------------------------
/app/routes/index.php:
--------------------------------------------------------------------------------
1 | set404(). Whatever function
10 | | you set will be called when a 404 error is encountered
11 | |
12 | */
13 | app()->set404(function () {
14 | response()->json('Resource not found', 404, true);
15 | });
16 |
17 | /*
18 | |--------------------------------------------------------------------------
19 | | Set up 500 handler
20 | |--------------------------------------------------------------------------
21 | |
22 | | Leaf provides a default 500 page, but you can create your own error
23 | | 500 handler by calling the setErrorHandler() method. The function
24 | | you set will be called when a 500 error is encountered
25 | |
26 | */
27 | app()->setErrorHandler(function () {
28 | response()->json('An error occured, our team has been notified', 500, true);
29 | });
30 |
31 | /*
32 | |--------------------------------------------------------------------------
33 | | Set up Controller namespace
34 | |--------------------------------------------------------------------------
35 | |
36 | | This allows you to directly use controller names instead of typing
37 | | the controller namespace first.
38 | |
39 | */
40 | app()->setNamespace('\App\Controllers');
41 |
42 | /*
43 | |--------------------------------------------------------------------------
44 | | Your application routes
45 | |--------------------------------------------------------------------------
46 | |
47 | | Leaf MVC automatically loads all files in the routes folder that
48 | | start with "_". We call these files route partials. An example
49 | | partial has been created for you.
50 | |
51 | | If you want to manually load routes, you can
52 | | create a file that doesn't start with "_" and manually require
53 | | it here like so:
54 | |
55 | */
56 | // require __DIR__ . '/custom-route.php';
57 |
--------------------------------------------------------------------------------
/app/views/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsphp/leafAPI/7a9e49275ca2672b6623b833e5f1593e5afd1b6f/app/views/.gitkeep
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "leafs/api",
3 | "description": "A lightweight PHP MVC framework for rapid API development.",
4 | "type": "library",
5 | "keywords": [
6 | "framework",
7 | "leaf",
8 | "leafPHP",
9 | "mvc",
10 | "leaf api",
11 | "api"
12 | ],
13 | "license": "MIT",
14 | "authors": [
15 | {
16 | "name": "Michael Darko",
17 | "email": "mickdd22@gmail.com",
18 | "homepage": "https://mychi.netlify.app",
19 | "role": "Maintainer"
20 | }
21 | ],
22 | "require": {
23 | "leafs/aloe": "dev-master",
24 | "illuminate/console": "^8.75",
25 | "leafs/blade": "*",
26 | "leafs/mvc-core": "*",
27 | "leafs/leaf": "^3.3",
28 | "leafs/logger": "*",
29 | "leafs/cors": "*",
30 | "leafs/auth": "*",
31 | "leafs/db": "*"
32 | },
33 | "require-dev": {
34 | "fakerphp/faker": "^1.16"
35 | },
36 | "autoload": {
37 | "psr-4": {
38 | "App\\": "app/",
39 | "Tests\\": "tests/",
40 | "Config\\": "config/",
41 | "App\\Http\\": "app/http/",
42 | "App\\Jobs\\": "app/jobs/",
43 | "App\\Lang\\": "app/lang/",
44 | "App\\Mail\\": "app/mail/",
45 | "App\\Views\\": "app/views/",
46 | "App\\Utils\\": "app/utils/",
47 | "App\\Events\\": "app/events/",
48 | "App\\Models\\": "app/models/",
49 | "App\\Workers\\": "app/workers/",
50 | "App\\Console\\": "app/console/",
51 | "App\\Scripts\\": "app/scripts/",
52 | "App\\Helpers\\": "app/helpers/",
53 | "App\\Channels\\": "app/channels/",
54 | "App\\Services\\": "app/services/",
55 | "App\\Middleware\\": "app/middleware/",
56 | "App\\Components\\": "app/components/",
57 | "App\\Controllers\\": "app/controllers/",
58 | "App\\Notifications\\": "app/notifications/",
59 | "App\\Database\\Seeds\\": "app/database/seeds/",
60 | "App\\Database\\Schema\\": "app/database/schema/",
61 | "App\\Database\\Factories\\": "app/database/factories/"
62 | }
63 | },
64 | "config": {
65 | "optimize-autoloader": true,
66 | "sort-packages": false,
67 | "allow-plugins": {
68 | "pestphp/pest-plugin": true
69 | }
70 | },
71 | "scripts": {
72 | "post-root-package-install": [
73 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"",
74 | "@php -r \"unlink('README.MD'); rename('README2.MD', 'README.MD');\""
75 | ],
76 | "post-create-project-cmd": [
77 | "@php leaf key:generate"
78 | ]
79 | },
80 | "minimum-stability": "dev",
81 | "prefer-stable": true
82 | }
83 |
--------------------------------------------------------------------------------
/config/app.php:
--------------------------------------------------------------------------------
1 | _env('APP_DOWN', false),
32 |
33 | /*
34 | |--------------------------------------------------------------------------
35 | | App debugging
36 | |--------------------------------------------------------------------------
37 | |
38 | | If debugging is enabled, Leaf will use its built-in error handler to
39 | | display diagnostic information for uncaught Exceptions, else it will
40 | | display a bare error page usable in production. You can set a
41 | | custom error page to display using `$app->setError`.
42 | |
43 | | You might want to turn this off in production.
44 | |
45 | */
46 | 'debug' => _env('APP_DEBUG', true),
47 |
48 | /*
49 | |--------------------------------------------------------------------------
50 | | Log directory
51 | |--------------------------------------------------------------------------
52 | |
53 | | This tells leaf which directory to save and look for logs.
54 | |
55 | */
56 | 'log.dir' => 'storage/logs/',
57 |
58 | /*
59 | |--------------------------------------------------------------------------
60 | | Log Enabled
61 | |--------------------------------------------------------------------------
62 | |
63 | | This enables or disables Leaf’s logger. Note that if log.enabled is
64 | | set to false. Leaf will skip initializing anything related to logs,
65 | | as such, you won't have access to $app->logger(),
66 | | $app->log or $app->logWriter.
67 | |
68 | */
69 | 'log.enabled' => true,
70 |
71 | /*
72 | |--------------------------------------------------------------------------
73 | | Log file
74 | |--------------------------------------------------------------------------
75 | |
76 | | This setting tells leaf which file to write logs to.
77 | |
78 | */
79 | 'log.file' => 'app.log',
80 |
81 | /*
82 | |--------------------------------------------------------------------------
83 | | Log level
84 | |--------------------------------------------------------------------------
85 | |
86 | | Leaf has these log levels:
87 | |
88 | | - \Leaf\Log::EMERGENCY
89 | | - \Leaf\Log::ALERT
90 | | - \Leaf\Log::CRITICAL
91 | | - \Leaf\Log::ERROR
92 | | - \Leaf\Log::WARN
93 | | - \Leaf\Log::NOTICE
94 | | - \Leaf\Log::INFO
95 | | - \Leaf\Log::DEBUG
96 | |
97 | */
98 | 'log.level' => \Leaf\Log::DEBUG,
99 |
100 | /*
101 | |--------------------------------------------------------------------------
102 | | Log open
103 | |--------------------------------------------------------------------------
104 | |
105 | | Takes in a boolean and determines whether Leaf should create
106 | | the specified log file if it doesn't exist.
107 | |
108 | */
109 | 'log.open' => true,
110 |
111 | /*
112 | |--------------------------------------------------------------------------
113 | | Log writer
114 | |--------------------------------------------------------------------------
115 | |
116 | | Use a custom log writer to direct logged messages
117 | | to the appropriate output destination.
118 | |
119 | */
120 | 'log.writer' => null,
121 |
122 | /*
123 | |--------------------------------------------------------------------------
124 | | Mode
125 | |--------------------------------------------------------------------------
126 | |
127 | | This is an identifier for the application’s current mode of operation.
128 | | The mode does not affect a Leaf application’s internal functionality.
129 | |
130 | */
131 | 'mode' => 'development',
132 |
133 | /*
134 | |--------------------------------------------------------------------------
135 | | Views path
136 | |--------------------------------------------------------------------------
137 | |
138 | | The relative or absolute path to the filesystem directory that
139 | | contains your Leaf application’s view files.
140 | |
141 | */
142 | 'views.path' => ViewsPath(null, false),
143 |
144 | /*
145 | |--------------------------------------------------------------------------
146 | | views cache path
147 | |--------------------------------------------------------------------------
148 | |
149 | | This config tells leaf where to save cached and compiled views.
150 | |
151 | */
152 | 'views.cachePath' => StoragePath('framework/views')
153 | ];
154 |
--------------------------------------------------------------------------------
/config/auth.php:
--------------------------------------------------------------------------------
1 | 'users',
16 |
17 | /*
18 | |--------------------------------------------------------------------------
19 | | Use session
20 | |--------------------------------------------------------------------------
21 | |
22 | | Use session based authentication instead of the default JWT based auth.
23 | |
24 | */
25 | 'USE_SESSION' => true,
26 |
27 | /*
28 | |--------------------------------------------------------------------------
29 | | Generate timestamps
30 | |--------------------------------------------------------------------------
31 | |
32 | | Automatically generate created_at/updated_at timestamps for register
33 | | and update methods
34 | |
35 | */
36 | 'USE_TIMESTAMPS' => true,
37 |
38 | /*
39 | |--------------------------------------------------------------------------
40 | | Set timestamps format
41 | |--------------------------------------------------------------------------
42 | |
43 | | Use this property to specify the format that you want your timestamps to be saved in.
44 | | Be aware that auth uses the leafs/date module, so the accepted formats are listed in the leafs/date documentation
45 | |
46 | */
47 | 'TIMESTAMP_FORMAT' => 'c',
48 |
49 | /*
50 | |--------------------------------------------------------------------------
51 | | Encode password
52 | |--------------------------------------------------------------------------
53 | |
54 | | Password encode is run when leaf wants to encode passwords on register
55 | | This exact method is used by default in Leaf, so you can set it to null
56 | | if you want to.
57 | |
58 | | You can set your own implementation instead of Password::hash
59 | |
60 | */
61 | 'PASSWORD_ENCODE' => function ($password) {
62 | return Password::hash($password);
63 | },
64 |
65 | /*
66 | |--------------------------------------------------------------------------
67 | | Verify Password
68 | |--------------------------------------------------------------------------
69 | |
70 | | This function is run to verify the password. This implementation is done
71 | | by default, so you can set it to null, and it will still work fine.
72 | |
73 | | You can add your own implementation instead of Password::verify
74 | |
75 | */
76 | 'PASSWORD_VERIFY' => function ($password, $hashedPassword) {
77 | return Password::verify($password, $hashedPassword);
78 | },
79 |
80 | /*
81 | |--------------------------------------------------------------------------
82 | | Password Key
83 | |--------------------------------------------------------------------------
84 | |
85 | | The default password key. Leaf will expect this key to hold passwords
86 | | in your database.
87 | |
88 | */
89 | 'PASSWORD_KEY' => 'password',
90 |
91 | /*
92 | |--------------------------------------------------------------------------
93 | | ID Key
94 | |--------------------------------------------------------------------------
95 | |
96 | | Set your primary key name. For instance, you might have used id_user instead of id.
97 | | This setting allows you to quickly switch your key name
98 | |
99 | */
100 | 'ID_KEY' => 'id',
101 |
102 | /*
103 | |--------------------------------------------------------------------------
104 | | Hide id
105 | |--------------------------------------------------------------------------
106 | |
107 | | Hide id field from user object returned in login, register and update
108 | |
109 | */
110 | 'HIDE_ID' => true,
111 |
112 | /*
113 | |--------------------------------------------------------------------------
114 | | Hide password
115 | |--------------------------------------------------------------------------
116 | |
117 | | Hide password from user object returned in login, register and update
118 | |
119 | */
120 | 'HIDE_PASSWORD' => true,
121 |
122 | /*
123 | |--------------------------------------------------------------------------
124 | | Login params error
125 | |--------------------------------------------------------------------------
126 | |
127 | | Error to show when the login params aren't found in db
128 | |
129 | */
130 | 'LOGIN_PARAMS_ERROR' => 'Username not registered!',
131 |
132 | /*
133 | |--------------------------------------------------------------------------
134 | | Password error
135 | |--------------------------------------------------------------------------
136 | |
137 | | Error to show when the login password is wrong
138 | |
139 | */
140 | 'LOGIN_PASSWORD_ERROR' => 'Password is incorrect!',
141 |
142 | /*
143 | |--------------------------------------------------------------------------
144 | | Session on register
145 | |--------------------------------------------------------------------------
146 | |
147 | | If true, a session will be created on a successful registration, else
148 | | you it'll be created on login rather.
149 | |
150 | */
151 | 'SESSION_ON_REGISTER' => false,
152 |
153 | /*
154 | |--------------------------------------------------------------------------
155 | | Session redirect on login
156 | |--------------------------------------------------------------------------
157 | |
158 | | When set to true, the options set in GUARD_LOGIN, GUARD_REGISTER and GUARD_HOME
159 | | will be used to redirect the user to the right page based on their state.
160 | | Set to false to not redirect on login
161 | |
162 | */
163 | 'SESSION_REDIRECT_ON_LOGIN' => true,
164 |
165 | /*
166 | |--------------------------------------------------------------------------
167 | | Session redirect on register
168 | |--------------------------------------------------------------------------
169 | |
170 | | When set to true, the options set in GUARD_LOGIN, GUARD_REGISTER and GUARD_HOME
171 | | will be used to redirect the user to the right page based on their state.
172 | | Set to false to not redirect on login
173 | |
174 | */
175 | 'SESSION_REDIRECT_ON_REGISTER' => true,
176 |
177 | /*
178 | |--------------------------------------------------------------------------
179 | | Session lifetime
180 | |--------------------------------------------------------------------------
181 | |
182 | | Set the lifetime of the session. After this time, the session will expire and the user will have to login again.
183 | | You can either use '1 day' format or as an integer: 86400
184 | | You can also set SESSION_LIFETIME to 0 to disable session expiration.
185 | |
186 | */
187 | 'SESSION_LIFETIME' => 60 * 60 * 24,
188 |
189 | /*
190 | |--------------------------------------------------------------------------
191 | | Login page route
192 | |--------------------------------------------------------------------------
193 | */
194 | 'GUARD_LOGIN' => '/auth/login',
195 |
196 | /*
197 | |--------------------------------------------------------------------------
198 | | Register page route
199 | |--------------------------------------------------------------------------
200 | */
201 | 'GUARD_REGISTER' => '/auth/register',
202 |
203 | /*
204 | |--------------------------------------------------------------------------
205 | | Logout route
206 | |--------------------------------------------------------------------------
207 | */
208 | 'GUARD_LOGOUT' => '/auth/logout',
209 |
210 | /*
211 | |--------------------------------------------------------------------------
212 | | Home page route
213 | |--------------------------------------------------------------------------
214 | */
215 | 'GUARD_HOME' => '/home',
216 |
217 | /*
218 | |--------------------------------------------------------------------------
219 | | JWT + Session
220 | |--------------------------------------------------------------------------
221 | |
222 | | Add an auth token to the auth session
223 | |
224 | */
225 | 'SAVE_SESSION_JWT' => false,
226 |
227 | /*
228 | |--------------------------------------------------------------------------
229 | | JWT Token Secret
230 | |--------------------------------------------------------------------------
231 | |
232 | | Secret string to encode JWT
233 | |
234 | */
235 | 'TOKEN_SECRET' => '@_leaf$0Secret!',
236 |
237 | /*
238 | |--------------------------------------------------------------------------
239 | | JWT Lifetime
240 | |--------------------------------------------------------------------------
241 | |
242 | | How long should JWT be valid for?
243 | |
244 | */
245 | 'TOKEN_LIFETIME' => 60 * 60 * 24 * 365
246 | ];
247 |
--------------------------------------------------------------------------------
/config/cors.php:
--------------------------------------------------------------------------------
1 | '*',
32 |
33 | /*
34 | |--------------------------------------------------------------------------
35 | | Configure allowed HTTP methods
36 | |--------------------------------------------------------------------------
37 | |
38 | | Configures the Access-Control-Allow-Methods CORS header.
39 | | Expects a comma-delimited string (ex: 'GET,PUT,POST') or
40 | | an array (ex: ['GET', 'PUT', 'POST'])
41 | |
42 | */
43 | 'methods' => 'GET,HEAD,PUT,PATCH,POST,DELETE',
44 |
45 | /*
46 | |--------------------------------------------------------------------------
47 | | Configure allowed HTTP headers
48 | |--------------------------------------------------------------------------
49 | |
50 | | Configures the Access-Control-Allow-Headers CORS header. Expects a
51 | | comma-delimited string (ex: 'Content-Type,Authorization') or
52 | | an array (ex: ['Content-Type', 'Authorization']). If not specified,
53 | | defaults to reflecting the headers specified in the request's
54 | | Access-Control-Request-Headers header.
55 | |
56 | */
57 | 'allowedHeaders' => '*',
58 |
59 | /*
60 | |--------------------------------------------------------------------------
61 | | Configure expose headers
62 | |--------------------------------------------------------------------------
63 | |
64 | | Configures the Access-Control-Expose-Headers CORS header. Expects
65 | | a comma-delimited string (ex: 'Content-Range,X-Content-Range')
66 | | or an array (ex: ['Content-Range', 'X-Content-Range']).
67 | | If not specified, no custom headers are exposed.
68 | |
69 | */
70 | 'exposedHeaders' => '',
71 |
72 | /*
73 | |--------------------------------------------------------------------------
74 | | Configure credentials
75 | |--------------------------------------------------------------------------
76 | |
77 | | Configures the Access-Control-Allow-Credentials CORS header.
78 | | Set to true to pass the header, otherwise it is omitted.
79 | |
80 | */
81 | 'credentials' => false,
82 |
83 | /*
84 | |--------------------------------------------------------------------------
85 | | Configure max age
86 | |--------------------------------------------------------------------------
87 | |
88 | | Configures the Access-Control-Max-Age CORS header. Set to
89 | | an integer to pass the header, otherwise it is omitted.
90 | |
91 | */
92 | 'maxAge' => null,
93 |
94 | /*
95 | |--------------------------------------------------------------------------
96 | | Configure preflight continue
97 | |--------------------------------------------------------------------------
98 | |
99 | | Pass the CORS preflight response to the next handler.
100 | |
101 | */
102 | 'preflightContinue' => false,
103 |
104 | /*
105 | |--------------------------------------------------------------------------
106 | | Log open
107 | |--------------------------------------------------------------------------
108 | |
109 | | Provides a status code to use for successful OPTIONS requests,
110 | | since some legacy browsers (IE11, various SmartTVs) choke on 204.
111 | |
112 | */
113 | 'optionsSuccessStatus' => 204,
114 | ];
115 |
--------------------------------------------------------------------------------
/config/csrf.php:
--------------------------------------------------------------------------------
1 | '_token',
27 | 'SECRET' => getenv('APP_KEY'),
28 | 'METHODS' => ['POST', 'PUT', 'PATCH', 'DELETE'],
29 | 'EXCEPT' => [
30 | // ... route list
31 | ]
32 | ];
33 |
--------------------------------------------------------------------------------
/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 eloquent is shown below to make development simple.
26 | |
27 | |
28 | | All database work in eloquent 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 | 'sqlite' => [
36 | 'driver' => 'sqlite',
37 | 'url' => _env('DATABASE_URL'),
38 | 'database' => _env('DB_DATABASE', AppPaths('databaseStorage') . '/database.sqlite'),
39 | 'prefix' => '',
40 | 'foreign_key_constraints' => _env('DB_FOREIGN_KEYS', true),
41 | ],
42 |
43 | 'mysql' => [
44 | 'driver' => 'mysql',
45 | 'url' => _env('DATABASE_URL'),
46 | 'host' => _env('DB_HOST', '127.0.0.1'),
47 | 'port' => _env('DB_PORT', '3306'),
48 | 'database' => _env('DB_DATABASE', 'forge'),
49 | 'username' => _env('DB_USERNAME', 'forge'),
50 | 'password' => _env('DB_PASSWORD', ''),
51 | 'unix_socket' => _env('DB_SOCKET', ''),
52 | 'charset' => _env('DB_CHARSET', 'utf8mb4'),
53 | 'collation' => _env('DB_COLLATION', 'utf8mb4_unicode_ci'),
54 | 'prefix' => '',
55 | 'prefix_indexes' => true,
56 | 'strict' => true,
57 | 'engine' => null,
58 | 'options' => extension_loaded('pdo_mysql') ? array_filter([
59 | PDO::MYSQL_ATTR_SSL_CA => _env('MYSQL_ATTR_SSL_CA'),
60 | ]) : [],
61 | ],
62 |
63 | 'pgsql' => [
64 | 'driver' => 'pgsql',
65 | 'url' => _env('DATABASE_URL'),
66 | 'host' => _env('DB_HOST', '127.0.0.1'),
67 | 'port' => _env('DB_PORT', '5432'),
68 | 'database' => _env('DB_DATABASE', 'forge'),
69 | 'username' => _env('DB_USERNAME', 'forge'),
70 | 'password' => _env('DB_PASSWORD', ''),
71 | 'charset' => _env('DB_CHARSET', 'utf8'),
72 | 'prefix' => '',
73 | 'prefix_indexes' => true,
74 | 'schema' => 'public',
75 | 'sslmode' => 'prefer',
76 | ],
77 |
78 | 'sqlsrv' => [
79 | 'driver' => 'sqlsrv',
80 | 'url' => _env('DATABASE_URL'),
81 | 'host' => _env('DB_HOST', 'localhost'),
82 | 'port' => _env('DB_PORT', '1433'),
83 | 'database' => _env('DB_DATABASE', 'forge'),
84 | 'username' => _env('DB_USERNAME', 'forge'),
85 | 'password' => _env('DB_PASSWORD', ''),
86 | 'charset' => _env('DB_CHARSET', 'utf8'),
87 | 'prefix' => '',
88 | 'prefix_indexes' => true,
89 | ],
90 | ],
91 | ];
92 |
--------------------------------------------------------------------------------
/config/paths.php:
--------------------------------------------------------------------------------
1 | 'app/console',
16 |
17 | 'config' => 'config',
18 |
19 | 'channels' => 'app/channels',
20 |
21 | 'components' => 'app/components',
22 |
23 | 'controllers' => 'app/controllers',
24 |
25 | 'databaseStorage' => 'storage/app/db',
26 |
27 | 'events' => 'app/events',
28 |
29 | 'factories' => 'app/database/factories',
30 |
31 | 'helpers' => 'app/helpers',
32 |
33 | 'jobs' => 'app/jobs',
34 |
35 | 'lib' => 'lib',
36 |
37 | 'mail' => 'app/mail',
38 |
39 | 'middleware' => 'app/middleware',
40 |
41 | 'migrations' => 'app/database/migrations',
42 |
43 | 'models' => 'app/models',
44 |
45 | 'routes' => 'app/routes',
46 |
47 | 'schema' => 'app/database/schema',
48 |
49 | 'scripts' => 'app/scripts',
50 |
51 | 'seeds' => 'app/database/seeds',
52 |
53 | 'services' => 'app/services',
54 |
55 | 'storage' => 'storage',
56 |
57 | 'utils' => 'app/utils',
58 |
59 | 'views' => 'app/views',
60 |
61 | 'workers' => 'app/workers',
62 | ];
63 |
--------------------------------------------------------------------------------
/config/view.php:
--------------------------------------------------------------------------------
1 | \Leaf\Blade::class,
14 |
15 | /*
16 | |--------------------------------------------------------------------------
17 | | Custom config method
18 | |--------------------------------------------------------------------------
19 | |
20 | | Configuration for your templating engine.
21 | |
22 | */
23 | 'config' => function ($config) {
24 | \Leaf\Config::get('views.blade')->configure($config['views'], $config['cache']);
25 | },
26 |
27 | /*
28 | |--------------------------------------------------------------------------
29 | | Custom render method
30 | |--------------------------------------------------------------------------
31 | |
32 | | This render method is triggered whenever render() is called
33 | | in your app if you're using a custom view engine.
34 | |
35 | */
36 | 'render' => null,
37 | ];
38 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | load();
27 | } catch (\Throwable $th) {
28 | trigger_error($th);
29 | }
30 |
31 | /*
32 | |--------------------------------------------------------------------------
33 | | Load Leaf configuration
34 | |--------------------------------------------------------------------------
35 | |
36 | | Leaf MVC allows you to customize Leaf and it's modules using
37 | | configuration files defined in the config folder. This line
38 | | loads the configuration files and makes them available to
39 | | your application.
40 | |
41 | */
42 | Leaf\Core::loadApplicationConfig();
43 | Leaf\Database::connect();
44 |
45 | /*
46 | |--------------------------------------------------------------------------
47 | | Initialise Leaf CMD
48 | |--------------------------------------------------------------------------
49 | |
50 | | Initialise aloe CLI
51 | |
52 | */
53 | $console = new \Aloe\Console("Leaf API", "v3.5.0");
54 |
55 | /*
56 | |--------------------------------------------------------------------------
57 | | Configure Aloe
58 | |--------------------------------------------------------------------------
59 | |
60 | | Set aloe environment to Leaf API
61 | |
62 | */
63 | \Aloe\Command\Config::$env = "API";
64 |
65 | /*
66 | |--------------------------------------------------------------------------
67 | | Add commands
68 | |--------------------------------------------------------------------------
69 | |
70 | | Add custom commands
71 | |
72 | */
73 | $console->register(\App\Console\ExampleCommand::class);
74 |
75 | /*
76 | |--------------------------------------------------------------------------
77 | | Run The console Application
78 | |--------------------------------------------------------------------------
79 | |
80 | | Transport water and dissolved substances to the rest of Leaf😂
81 | |
82 | */
83 | $console->run();
84 |
--------------------------------------------------------------------------------
/lib/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsphp/leafAPI/7a9e49275ca2672b6623b833e5f1593e5afd1b6f/lib/.gitkeep
--------------------------------------------------------------------------------
/public/.htaccess:
--------------------------------------------------------------------------------
1 |
2 |
3 | Options -MultiViews -Indexes
4 |
5 |
6 | RewriteEngine On
7 |
8 | # Handle Authorization Header
9 | RewriteCond %{HTTP:Authorization} .
10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
11 |
12 | # Redirect Trailing Slashes If Not A Folder...
13 | RewriteCond %{REQUEST_FILENAME} !-d
14 | RewriteCond %{REQUEST_URI} (.+)/$
15 | RewriteRule ^ %1 [L,R=301]
16 |
17 | # Handle Front Controller...
18 | RewriteCond %{REQUEST_FILENAME} !-d
19 | RewriteCond %{REQUEST_FILENAME} !-f
20 | RewriteRule ^ index.php [L]
21 |
22 |
--------------------------------------------------------------------------------
/public/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsphp/leafAPI/7a9e49275ca2672b6623b833e5f1593e5afd1b6f/public/assets/.gitkeep
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsphp/leafAPI/7a9e49275ca2672b6623b833e5f1593e5afd1b6f/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.php:
--------------------------------------------------------------------------------
1 | load();
37 | } catch (\Throwable $th) {
38 | trigger_error($th);
39 | }
40 |
41 | /*
42 | |--------------------------------------------------------------------------
43 | | Load application paths
44 | |--------------------------------------------------------------------------
45 | |
46 | | Decline static file requests back to the PHP built-in webserver
47 | |
48 | */
49 | if (php_sapi_name() === 'cli-server') {
50 | $path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
51 |
52 | if (is_string($path) && __FILE__ !== $path && is_file($path)) {
53 | return false;
54 | }
55 |
56 | unset($path);
57 | }
58 |
59 | /*
60 | |--------------------------------------------------------------------------
61 | | Attach blade view
62 | |--------------------------------------------------------------------------
63 | |
64 | | Since blade no longer ships with Leaf by default, we
65 | | can attach blade back to Leaf. If you want to use blade
66 | | in your application, you can uncomment the line below.
67 | |
68 | */
69 | // Leaf\Config::attachView(\Leaf\Blade::class);
70 |
71 | /*
72 | |--------------------------------------------------------------------------
73 | | Load Leaf configuration
74 | |--------------------------------------------------------------------------
75 | |
76 | | Leaf MVC allows you to customize Leaf and it's modules using
77 | | configuration files defined in the config folder. This line
78 | | loads the configuration files and makes them available to
79 | | your application.
80 | |
81 | */
82 | Leaf\Core::loadApplicationConfig();
83 |
84 | /*
85 | |--------------------------------------------------------------------------
86 | | Sync Leaf Db with ORM and connect
87 | |--------------------------------------------------------------------------
88 | |
89 | | Sync Leaf Db with ORM and connect to the database
90 | | This allows you to use Leaf Db without having
91 | | to initialize it in your controllers.
92 | |
93 | | If you want to use a different connection from those
94 | | used in your models, you can remove the line below and
95 | | add your own connection with:
96 | | db()->connect(...)
97 | |
98 | | **Uncomment the line below to use Leaf Db**
99 | | **You don't need this line to use Leaf Auth**
100 | */
101 | // \Leaf\Database::initDb();
102 |
103 | /*
104 | |--------------------------------------------------------------------------
105 | | Load custom libraries
106 | |--------------------------------------------------------------------------
107 | |
108 | | You can load your custom libraries here. If you have
109 | | anything defined in your lib folder, you can load
110 | | them here. Simply uncomment the line below.
111 | |
112 | */
113 | // \Leaf\Core::loadLibs();
114 |
115 | /*
116 | |--------------------------------------------------------------------------
117 | | Run your Leaf MVC application
118 | |--------------------------------------------------------------------------
119 | |
120 | | This line brings in all your routes and starts your application
121 | |
122 | */
123 | \Leaf\Core::runApplication();
124 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 | Disallow:
3 |
--------------------------------------------------------------------------------
/public/web.config:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/storage/app/public/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/storage/framework/views/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/storage/logs/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------