1
0
Fork 0
mirror of https://github.com/archtechx/laravel-tips.git synced 2025-12-12 21:34:03 +00:00
This commit is contained in:
Samuel Štancl 2021-04-06 21:14:55 +02:00
parent 1beb9dd34c
commit 8dae8d1250
13 changed files with 79 additions and 60 deletions

BIN
.DS_Store vendored

Binary file not shown.

View file

@ -1,62 +1,42 @@
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400"></a></p> # Laravel Code Tips
<p align="center"> This project is a simple Laravel application that uses:
<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a> - Ryan Chandler's [Orbit](https://github.com/ryangjchandler/orbit) package for storing data in markdown files
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a> - custom command for generating a static version of the website (this will later be extracted to a separate and more robust package)
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a> - [Flipp](https://useflipp.io) for beautiful OpenGraph & Twitter Card previews
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>
## 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). 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.
- [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).
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/)** 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`.
- **[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)**
## Contributing To generate the static HTML run `composer generate` and to preview it run `composer serve`.
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).

View file

@ -4,6 +4,7 @@ namespace App\Models;
use App\Twitter\Tweet; use App\Twitter\Tweet;
use App\Twitter\TwitterImage; use App\Twitter\TwitterImage;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -21,7 +22,7 @@ use Illuminate\Support\Str;
* @property string|null $thread_id * @property string|null $thread_id
* @property string[] $images * @property string[] $images
* @property-read Author $author * @property-read Author $author
* @property-read Thread $thread * @property-read Thread|null $thread
* @property-read \Illuminate\Eloquent\Collection|Image[] $images * @property-read \Illuminate\Eloquent\Collection|Image[] $images
* @property-read string $tweet_url * @property-read string $tweet_url
*/ */
@ -89,6 +90,8 @@ class Tip extends Model
$model->created_at ??= now(); $model->created_at ??= now();
$model->slug ??= Str::slug($model->title); $model->slug ??= Str::slug($model->title);
}); });
static::addGlobalScope('order', fn (Builder $query) => $query->orderBy('created_at', 'desc'));
} }
public function getKeyName() public function getKeyName()

View file

@ -46,8 +46,8 @@
"@php artisan key:generate --ansi" "@php artisan key:generate --ansi"
], ],
"seed": "(rm -f content/**/*.md || true) && php artisan orbit:clear && php artisan db:seed", "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 http://127.0.0.1:7777",
"generate": "@php artisan html:generate static 127.0.0.1:7777" "serve": "@php -S 127.0.0.1:7777 -t static"
}, },
"extra": { "extra": {
"laravel": { "laravel": {

BIN
public/apple-touch-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

BIN
public/favicon-16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
public/favicon-32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 0 B

After

Width:  |  Height:  |  Size: 15 KiB

Before After
Before After

BIN
public/og.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

View file

@ -1,13 +1,49 @@
@props([
'title' => null,
'preview' => null,
])
@php
$title = $title
? $title . ' | Laravel Code Tips'
: 'Laravel Code Tips';
@endphp
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title> <title>{{ $title }}</title>
<link rel="stylesheet" href="{{ mix('css/app.css') }}"> <link rel="stylesheet" href="{{ mix('css/app.css') }}">
<script type="module" src="{{ mix('js/app.js') }}"></script> <script type="module" src="{{ mix('js/app.js') }}"></script>
<link href="https://fonts.rcvd.io/iA%20Writer/stylesheet.css" rel="stylesheet" type="text/css"> <link href="https://fonts.rcvd.io/iA%20Writer/stylesheet.css" rel="stylesheet" type="text/css">
<meta property="og:type" content="website" />
<meta property="og:site_name" content="Laravel Code Tips">
<meta property="og:title" content="{{ $title }}" />
<meta property="og:description" content="Make your Laravel code cleaner, faster, and safer." />
@if($preview)
<meta property="og:image" content="https://i.useflipp.com/g6demrp3y3rz.png?content={{ urlencode($preview) }}" />
<meta property="twitter:image" content="https://i.useflipp.com/g6demrp3y3rz.png?content={{ urlencode($preview) }}" />
@else
<meta property="og:image" content="{{ asset('og.png') }}" />
<meta property="twitter:image" content="{{ asset('og.png') }}" />
@endif
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="LaravelCodeTips">
<meta name="twitter:title" content="{{ $title }}">
<meta name="twitter:description" content="Make your Laravel code cleaner, faster, and safer.">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<meta name="theme-color" content="#fa7c4c">
</head> </head>
<body class="antialiased bg-white"> <body class="antialiased bg-white">
<div class="w-full p-3 text-center min-h-screen flex justify-between flex-col"> <div class="w-full p-3 text-center min-h-screen flex justify-between flex-col">
@ -15,7 +51,7 @@
<footer class="space-y-2 text-gray-700 text-sm"> <footer class="space-y-2 text-gray-700 text-sm">
<p>Found an error? Contact us at <a href="mailto:hello@laravel-code.tips" class="link">support@laravel-code.tips</a>.</p> <p>Found an error? Contact us at <a href="mailto:hello@laravel-code.tips" class="link">support@laravel-code.tips</a>.</p>
<p>Want to share a tip? Submit it <a href="https://airtable.com/shrBX2ZAfnuAXh3up" target="_blank" class="link">here</a>.</p> <p>Want to share a tip? Submit it <a href="https://github.com/stancl/laravel-tips" target="_blank" class="link">here</a>.</p>
</footer> </footer>
</div> </div>
</body> </body>

View file

@ -1,4 +1,4 @@
<x:layout> <x:layout :title="$thread->title">
<main class="mx-auto flex justify-between items-start gap-8"> <main class="mx-auto flex justify-between items-start gap-8">
<aside class="flex flex-col gap-2 mt-60"> <aside class="flex flex-col gap-2 mt-60">
<h2 class="text-2xl font-medium"> <h2 class="text-2xl font-medium">

View file

@ -1,4 +1,4 @@
<x:layout> <x:layout :title="$tip->title">
<main class="mx-auto flex justify-between items-center gap-8"> <main class="mx-auto flex justify-between items-center gap-8">
<aside class="flex flex-col gap-2"> <aside class="flex flex-col gap-2">
<h2 class="text-2xl font-medium"> <h2 class="text-2xl font-medium">

View file

@ -21,14 +21,14 @@ Route::middleware('static')->group(function () {
return view('tips.index', ['tips' => Tip::all()]); return view('tips.index', ['tips' => Tip::all()]);
})->name('tip.index'); })->name('tip.index');
Route::get('/tips/{tip}', function (Tip $tip) {
return view('tips.show', compact('tip'));
})->name('tip.show');
Route::get('/threads/{thread}', function (Thread $thread) { Route::get('/threads/{thread}', function (Thread $thread) {
return view('threads.show', [ return view('threads.show', [
'thread' => $thread, 'thread' => $thread,
'tips' => $thread->tips, 'tips' => $thread->tips,
]); ]);
})->name('thread.show'); })->name('thread.show');
Route::get('/{tip}', function (Tip $tip) {
return view('tips.show', compact('tip'));
})->name('tip.show');
}); });