diff --git a/.DS_Store b/.DS_Store index 1c4abf2..f46d661 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README.md b/README.md index e1dcd2e..020c5e5 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,42 @@ -
+# Laravel Code Tips - +This project is a simple Laravel application that uses: +- Ryan Chandler's [Orbit](https://github.com/ryangjchandler/orbit) package for storing data in markdown files +- custom command for generating a static version of the website (this will later be extracted to a separate and more robust package) +- [Flipp](https://useflipp.io) for beautiful OpenGraph & Twitter Card previews -## About Laravel +The live version can be found on [laravel-code.tips](https://laravel-code.tips) or if you like emojis, that's [💻🔥⚡️💡.y.at](https://💻🔥⚡️💡.y.at). -Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: +Definitely feel free to submit content; it can be a great way to promote your work (not that you can't submit others' tips, we accept all that are good!). -- [Simple, fast routing engine](https://laravel.com/docs/routing). -- [Powerful dependency injection container](https://laravel.com/docs/container). -- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. -- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). -- Database agnostic [schema migrations](https://laravel.com/docs/migrations). -- [Robust background job processing](https://laravel.com/docs/queues). -- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). +Right now all tips should be on Twitter, but later we'll make it easier to add them standalone as well. That said, it's best to share your work on your Twitter profile before adding it here, since we link back to your Twitter post & profile. -Laravel is accessible, powerful, and provides tools required for large, robust applications. +## Submitting tips -## Learning Laravel +Open a PR adding a new file to `content/tips`. The file name should be a unique slug of the tip. The content should look like this: +```md +--- +title: 'Use strict comparison' +tweet_id: '1272826452652810240' +thread_slug: laravel-clean-code-tactics +author_username: samuelstancl +images: + - 'https://pbs.twimg.com/media/Ean722QXgAENwmW.jpg' +created_at: 2021-04-06T16:07:36+00:00 +slug: use-strict-comparison +--- -Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. +ALWAYS use strict comparison (=== and !==). If needed, cast things go the correct type before comparing. Better than weird == results -If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. +Also consider enabling strict types in your code. This will prevent passing variables of wrong data types to functions +``` -## Laravel Sponsors +The `slug` matches the file name, the `author_username` is the Twitter handle of the tip author, `tweet_id` is the id of the tweet with the tip, and `images` is an array of images that should be shown between the heading and the content. -We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell). +## Local setup -### Premium Partners +If you'd like to seed the database with content, create a new Twitter application and set the `TWITTER_TOKEN` variable in `.env` to the Bearer token of the app. That said, you likely won't need this because all the default data is available in this repository already. So you only need to do this if you want to add a lot of tweets in bulk. -- **[Vehikl](https://vehikl.com/)** -- **[Tighten Co.](https://tighten.co)** -- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** -- **[64 Robots](https://64robots.com)** -- **[Cubet Techno Labs](https://cubettech.com)** -- **[Cyber-Duck](https://cyber-duck.co.uk)** -- **[Many](https://www.many.co.uk)** -- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)** -- **[DevSquad](https://devsquad.com)** -- **[Curotec](https://www.curotec.com/)** -- **[OP.GG](https://op.gg)** +Otherwise, the project doesn't require any database, so you can just `git clone` it and open it in your browser, e.g. using Valet or `artisan serve`. -## Contributing - -Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). - -## Code of Conduct - -In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). - -## Security Vulnerabilities - -If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. - -## License - -The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). +To generate the static HTML run `composer generate` and to preview it run `composer serve`. diff --git a/app/Models/Tip.php b/app/Models/Tip.php index 6461034..a1aa77e 100644 --- a/app/Models/Tip.php +++ b/app/Models/Tip.php @@ -4,6 +4,7 @@ namespace App\Models; use App\Twitter\Tweet; use App\Twitter\TwitterImage; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -21,7 +22,7 @@ use Illuminate\Support\Str; * @property string|null $thread_id * @property string[] $images * @property-read Author $author - * @property-read Thread $thread + * @property-read Thread|null $thread * @property-read \Illuminate\Eloquent\Collection|Image[] $images * @property-read string $tweet_url */ @@ -89,6 +90,8 @@ class Tip extends Model $model->created_at ??= now(); $model->slug ??= Str::slug($model->title); }); + + static::addGlobalScope('order', fn (Builder $query) => $query->orderBy('created_at', 'desc')); } public function getKeyName() diff --git a/composer.json b/composer.json index b63332b..ee5f1ea 100644 --- a/composer.json +++ b/composer.json @@ -46,8 +46,8 @@ "@php artisan key:generate --ansi" ], "seed": "(rm -f content/**/*.md || true) && php artisan orbit:clear && php artisan db:seed", - "serve": "@php -S http://127.0.0.1:7777 -t static", - "generate": "@php artisan html:generate static 127.0.0.1:7777" + "generate": "@php artisan html:generate static http://127.0.0.1:7777", + "serve": "@php -S 127.0.0.1:7777 -t static" }, "extra": { "laravel": { diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png new file mode 100644 index 0000000..2bcf432 Binary files /dev/null and b/public/apple-touch-icon.png differ diff --git a/public/favicon-16x16.png b/public/favicon-16x16.png new file mode 100644 index 0000000..80df48b Binary files /dev/null and b/public/favicon-16x16.png differ diff --git a/public/favicon-32x32.png b/public/favicon-32x32.png new file mode 100644 index 0000000..9a1b092 Binary files /dev/null and b/public/favicon-32x32.png differ diff --git a/public/favicon.ico b/public/favicon.ico index e69de29..5fe169d 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ diff --git a/public/og.png b/public/og.png new file mode 100644 index 0000000..1f4587c Binary files /dev/null and b/public/og.png differ diff --git a/resources/views/components/layout.blade.php b/resources/views/components/layout.blade.php index 7f1d391..f2f2a47 100644 --- a/resources/views/components/layout.blade.php +++ b/resources/views/components/layout.blade.php @@ -1,13 +1,49 @@ +@props([ + 'title' => null, + 'preview' => null, +]) + +@php + $title = $title + ? $title . ' | Laravel Code Tips' + : 'Laravel Code Tips'; +@endphp + -