forked from laracasts/eloquent-performance-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a4fd4eb
Showing
2,580 changed files
with
560,762 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
lesson-01-measuring-your-database-performance/.editorconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 |
46 changes: 46 additions & 0 deletions
46
lesson-01-measuring-your-database-performance/.env.example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
APP_NAME=Laravel | ||
APP_ENV=local | ||
APP_KEY= | ||
APP_DEBUG=true | ||
APP_URL=http://localhost | ||
|
||
LOG_CHANNEL=stack | ||
|
||
DB_CONNECTION=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=laravel | ||
DB_USERNAME=root | ||
DB_PASSWORD= | ||
|
||
BROADCAST_DRIVER=log | ||
CACHE_DRIVER=file | ||
QUEUE_CONNECTION=sync | ||
SESSION_DRIVER=file | ||
SESSION_LIFETIME=120 | ||
|
||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
REDIS_PORT=6379 | ||
|
||
MAIL_MAILER=smtp | ||
MAIL_HOST=smtp.mailtrap.io | ||
MAIL_PORT=2525 | ||
MAIL_USERNAME=null | ||
MAIL_PASSWORD=null | ||
MAIL_ENCRYPTION=null | ||
MAIL_FROM_ADDRESS=null | ||
MAIL_FROM_NAME="${APP_NAME}" | ||
|
||
AWS_ACCESS_KEY_ID= | ||
AWS_SECRET_ACCESS_KEY= | ||
AWS_DEFAULT_REGION=us-east-1 | ||
AWS_BUCKET= | ||
|
||
PUSHER_APP_ID= | ||
PUSHER_APP_KEY= | ||
PUSHER_APP_SECRET= | ||
PUSHER_APP_CLUSTER=mt1 | ||
|
||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" | ||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* text=auto | ||
*.css linguist-vendored | ||
*.scss linguist-vendored | ||
*.js linguist-vendored | ||
CHANGELOG.md export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/node_modules | ||
/public/hot | ||
/public/storage | ||
/storage/*.key | ||
/vendor | ||
.env | ||
.env.backup | ||
.phpunit.result.cache | ||
Homestead.json | ||
Homestead.yaml | ||
npm-debug.log | ||
yarn-error.log |
21 changes: 21 additions & 0 deletions
21
lesson-01-measuring-your-database-performance/.php_cs.dist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
// Reference: http://cs.sensiolabs.org/ | ||
|
||
return PhpCsFixer\Config::create() | ||
->setUsingCache(false) | ||
->setRiskyAllowed(true) | ||
->setRules([ | ||
'@PHP70Migration' => true, | ||
'@PHP71Migration' => true, | ||
'@PSR2' => true, | ||
'@Symfony' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'increment_style' => ['style' => 'post'], | ||
'no_multiline_whitespace_before_semicolons' => true, | ||
'not_operator_with_successor_space' => true, | ||
'ordered_imports' => ['sortAlgorithm' => 'alpha'], | ||
'semicolon_after_instruction' => false, | ||
'strict_comparison' => true, | ||
'yoda_style' => false, | ||
]); |
13 changes: 13 additions & 0 deletions
13
lesson-01-measuring-your-database-performance/.styleci.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
php: | ||
preset: laravel | ||
disabled: | ||
- unused_use | ||
finder: | ||
not-name: | ||
- index.php | ||
- server.php | ||
js: | ||
finder: | ||
not-name: | ||
- webpack.mix.js | ||
css: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# How to | ||
|
||
## Vendor differences | ||
|
||
In some lessons, the source code is slightly different, depending on the database type (MySQL, Postgres and SQLite). When this happens, you'll see a database driver check in the source code that looks something like this: | ||
|
||
```php | ||
if (config('database.default') === 'pgsql') { | ||
// ... | ||
} | ||
``` | ||
|
||
In some cases, it's not possible to create variations for all three database types, and an exception will be thrown instead. | ||
|
||
```php | ||
if (config('database.default') === 'sqlite') { | ||
throw new \Exception('This lesson does not support SQLite.'); | ||
} | ||
``` | ||
|
||
## Installation | ||
|
||
To test this demo application, please follow these instructions. | ||
|
||
First, go to the lesson's source code directory. | ||
|
||
Next, install the PHP vendor dependencies using [Composer](https://getcomposer.org/): | ||
|
||
```sh | ||
composer install | ||
``` | ||
|
||
Next, copy the example configuration. You can do this from the command line, or by simply copying the `.env.example` file and saving it as `.env`. | ||
|
||
```sh | ||
cp .env.example .env | ||
``` | ||
|
||
Next, generate an application key by running the `key:generate` Artisan command: | ||
|
||
```sh | ||
php artisan key:generate | ||
``` | ||
|
||
Next, you'll need to configure a database. You can use the MySQL, Postgres, or SQLite drivers. To do this, update the `DB_CONNECTION` value in your `.env` file: | ||
|
||
```bash | ||
DB_CONNECTION=mysql # MySQL | ||
DB_CONNECTION=pgsql # Postgres | ||
DB_CONNECTION=sqlite # SQLite | ||
``` | ||
|
||
You will likely also need to edit the other database connection values as needed for your system, such as the database host (`DB_HOST`), database port (`DB_PORT`), database name (`DB_DATABASE`), database user (`DB_USERNAME`) and database password (`DB_PASSWORD`). | ||
|
||
If you're using SQLite, you can generate an SQLite database file by running the following command: | ||
|
||
```bash | ||
touch database/database.sqlite | ||
``` | ||
|
||
Be sure to see the [database section](https://laravel.com/docs/database) of the Laravel documentation if you're having trouble establishing a database connection. | ||
|
||
Once your database connection has been setup, run the database migrations: | ||
|
||
```sh | ||
php artisan migrate | ||
``` | ||
|
||
Next, run the database seeder to populate the database with some sample data: | ||
|
||
```sh | ||
php artisan db:seed | ||
``` | ||
|
||
Now you're ready to go! | ||
|
||
If you're using [Laravel Valet](https://laravel.com/docs/valet), [Laravel Homestead](https://laravel.com/docs/valet), or some other local development environment, view your website there as you normally would. Alternatively, you can also use the built-in PHP server: | ||
|
||
```sh | ||
php artisan serve | ||
``` | ||
|
||
This command will output an address where you can then view the site. | ||
|
||
Enjoy! 😊 |
13 changes: 13 additions & 0 deletions
13
lesson-01-measuring-your-database-performance/app/Company.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Company extends Model | ||
{ | ||
public function users() | ||
{ | ||
return $this->hasMany(User::class); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
lesson-01-measuring-your-database-performance/app/Console/Kernel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Console; | ||
|
||
use Illuminate\Console\Scheduling\Schedule; | ||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | ||
|
||
class Kernel extends ConsoleKernel | ||
{ | ||
/** | ||
* The Artisan commands provided by your application. | ||
* | ||
* @var array | ||
*/ | ||
protected $commands = [ | ||
// | ||
]; | ||
|
||
/** | ||
* Define the application's command schedule. | ||
* | ||
* @param \Illuminate\Console\Scheduling\Schedule $schedule | ||
* @return void | ||
*/ | ||
protected function schedule(Schedule $schedule) | ||
{ | ||
// $schedule->command('inspire')->hourly(); | ||
} | ||
|
||
/** | ||
* Register the commands for the application. | ||
* | ||
* @return void | ||
*/ | ||
protected function commands() | ||
{ | ||
$this->load(__DIR__.'/Commands'); | ||
|
||
require base_path('routes/console.php'); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
lesson-01-measuring-your-database-performance/app/Exceptions/Handler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; | ||
use Throwable; | ||
|
||
class Handler extends ExceptionHandler | ||
{ | ||
/** | ||
* A list of the exception types that are not reported. | ||
* | ||
* @var array | ||
*/ | ||
protected $dontReport = [ | ||
// | ||
]; | ||
|
||
/** | ||
* A list of the inputs that are never flashed for validation exceptions. | ||
* | ||
* @var array | ||
*/ | ||
protected $dontFlash = [ | ||
'password', | ||
'password_confirmation', | ||
]; | ||
|
||
/** | ||
* Report or log an exception. | ||
* | ||
* @param \Throwable $exception | ||
* @return void | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function report(Throwable $exception) | ||
{ | ||
parent::report($exception); | ||
} | ||
|
||
/** | ||
* Render an exception into an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Throwable $exception | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
* | ||
* @throws \Throwable | ||
*/ | ||
public function render($request, Throwable $exception) | ||
{ | ||
return parent::render($request, $exception); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
lesson-01-measuring-your-database-performance/app/Http/Controllers/Controller.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; | ||
use Illuminate\Foundation\Bus\DispatchesJobs; | ||
use Illuminate\Foundation\Validation\ValidatesRequests; | ||
use Illuminate\Routing\Controller as BaseController; | ||
|
||
class Controller extends BaseController | ||
{ | ||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; | ||
} |
18 changes: 18 additions & 0 deletions
18
lesson-01-measuring-your-database-performance/app/Http/Controllers/UsersController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\User; | ||
|
||
class UsersController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$users = User::query() | ||
->with('company') | ||
->orderBy('name') | ||
->simplePaginate(); | ||
|
||
return view('users', ['users' => $users]); | ||
} | ||
} |
Oops, something went wrong.