From 9c430b95938bb872e206070810e8a51d98497520 Mon Sep 17 00:00:00 2001 From: Dym Sohin Date: Fri, 9 Aug 2024 13:52:23 +0200 Subject: [PATCH] connect to db --- .env | 4 +- .../Controllers/RegisteredUserController.php | 2 +- app/Http/Controllers/SessionController.php | 2 +- app/Models/Article.php | 27 +-------- ...{layout-admin.php => layout-dashboard.php} | 4 +- .../2024_08_09_112756_create_articles.php | 37 ++++++++++++ public/css/{admin.css => dashboard.css} | 0 ...dashboard.blade.php => articles.blade.php} | 6 +- resources/views/auth/login.blade.php | 4 +- resources/views/auth/register.blade.php | 7 ++- resources/views/components/input.blade.php | 60 +++++++++++++------ ...n.blade.php => layout-dashboard.blade.php} | 4 +- resources/views/components/tag.blade.php | 2 +- resources/views/edit.blade.php | 4 +- resources/views/new.blade.php | 8 +-- resources/views/tag.blade.php | 7 --- routes/web.php | 4 +- 17 files changed, 110 insertions(+), 72 deletions(-) rename app/View/Components/{layout-admin.php => layout-dashboard.php} (80%) create mode 100644 database/migrations/2024_08_09_112756_create_articles.php rename public/css/{admin.css => dashboard.css} (100%) rename resources/views/{dashboard.blade.php => articles.blade.php} (67%) rename resources/views/components/{layout-admin.blade.php => layout-dashboard.blade.php} (91%) delete mode 100644 resources/views/tag.blade.php diff --git a/.env b/.env index 497a145..5a17487 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -APP_NAME=Laravel +APP_NAME=dym APP_ENV=local APP_KEY=base64:/4iQMUGojyypXAMaOjvIRIHHG+a/cbY+2KLC2ToQYHQ= APP_DEBUG=true @@ -52,7 +52,7 @@ MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null -MAIL_FROM_ADDRESS="hello@example.com" +MAIL_FROM_ADDRESS="re@dym.sh" MAIL_FROM_NAME="${APP_NAME}" AWS_ACCESS_KEY_ID= diff --git a/app/Http/Controllers/RegisteredUserController.php b/app/Http/Controllers/RegisteredUserController.php index 6fd1b9e..a2bba01 100644 --- a/app/Http/Controllers/RegisteredUserController.php +++ b/app/Http/Controllers/RegisteredUserController.php @@ -26,6 +26,6 @@ class RegisteredUserController extends Controller Auth::login( $user ); - return redirect('/admin'); + return redirect('/articles'); } } diff --git a/app/Http/Controllers/SessionController.php b/app/Http/Controllers/SessionController.php index 7decb33..34745a1 100644 --- a/app/Http/Controllers/SessionController.php +++ b/app/Http/Controllers/SessionController.php @@ -27,7 +27,7 @@ class SessionController extends Controller request()->session()->regenerate(); - return redirect('/dashboard'); + return redirect('/articles'); } public function destroy() diff --git a/app/Models/Article.php b/app/Models/Article.php index 2f01c5d..cadd27e 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -6,32 +6,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; -class Article //extends Model +class Article extends Model { - use HasFactory; + protected $table = 'articles'; - public static function all(): array { - return [ - [ 'id' => 1, - 'title' => 'First One', - 'slug' => '1st', - 'body' => 'First!!1
- lol', - ], - [ 'id' => 2, - 'title' => 'Second One', - 'slug' => '2nd', - 'body' => 'Second i do concour
- lmfao', - ], - [ 'id' => 3, - 'title' => 'Third One', - 'slug' => '3rd', - 'body' => 'Third indeed
- xD', - ], - ]; - } + use HasFactory; public static function find(string $slug): array { diff --git a/app/View/Components/layout-admin.php b/app/View/Components/layout-dashboard.php similarity index 80% rename from app/View/Components/layout-admin.php rename to app/View/Components/layout-dashboard.php index 7f1ca3e..c2d8c93 100644 --- a/app/View/Components/layout-admin.php +++ b/app/View/Components/layout-dashboard.php @@ -6,7 +6,7 @@ use Closure; use Illuminate\Contracts\View\View; use Illuminate\View\Component; -class layout-admin extends Component +class layout_dashboard extends Component { /** * Create a new component instance. @@ -21,6 +21,6 @@ class layout-admin extends Component */ public function render(): View|Closure|string { - return view('components.layout-admin'); + return view('components.layout-dashboard'); } } diff --git a/database/migrations/2024_08_09_112756_create_articles.php b/database/migrations/2024_08_09_112756_create_articles.php new file mode 100644 index 0000000..a1df494 --- /dev/null +++ b/database/migrations/2024_08_09_112756_create_articles.php @@ -0,0 +1,37 @@ +id(); + $table->string('slug'); + $table->string('title'); + $table->text('body'); + $table->integer('category'); + $table->boolean('is_collection'); + $table->integer('tag_1'); + $table->integer('tag_2'); + $table->integer('tag_3'); + $table->integer('tag_4'); + $table->integer('tag_5'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('articles'); + } +}; diff --git a/public/css/admin.css b/public/css/dashboard.css similarity index 100% rename from public/css/admin.css rename to public/css/dashboard.css diff --git a/resources/views/dashboard.blade.php b/resources/views/articles.blade.php similarity index 67% rename from resources/views/dashboard.blade.php rename to resources/views/articles.blade.php index 740b855..d925435 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/articles.blade.php @@ -1,4 +1,4 @@ - +
    @foreach($articles as $article) @@ -6,4 +6,6 @@ @endforeach
-
+// todo other lists; stats + + diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 9a8eaf4..2f3dc9b 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -1,3 +1,3 @@ - + - + diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 76e9edf..7cf06df 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -1,4 +1,7 @@ - + + + +
@csrf @@ -23,5 +26,3 @@
- -
diff --git a/resources/views/components/input.blade.php b/resources/views/components/input.blade.php index 0421907..bb6991c 100644 --- a/resources/views/components/input.blade.php +++ b/resources/views/components/input.blade.php @@ -1,21 +1,47 @@ -@if( 'hidden' !== $attributes['type'] ) - -
- +@if( 'hidden' === $attributes['type'] ) merge()->filter(fn ($value, $key) => !in_array($key, ['title'])) }} - > + name="{{ $slot }}" + {{ $attributes->merge() }} + > -@error( "$slot" ) -

{{ $message }}

-@enderror -
+@elseif( 'textarea' == $attributes['type'] ) + +
+ + + + @error( "$slot" ) +

{{ $message }}

+ @enderror +
+ +@else + +
+ + merge()->filter(fn ($value, $key) => !in_array($key, ['title'])) }} + > + + @error( "$slot" ) +

{{ $message }}

+ @enderror +
@endif \ No newline at end of file diff --git a/resources/views/components/layout-admin.blade.php b/resources/views/components/layout-dashboard.blade.php similarity index 91% rename from resources/views/components/layout-admin.blade.php rename to resources/views/components/layout-dashboard.blade.php index 83b7f07..f07d98f 100644 --- a/resources/views/components/layout-admin.blade.php +++ b/resources/views/components/layout-dashboard.blade.php @@ -3,7 +3,7 @@ {{ request()->path() }} - + @@ -13,7 +13,7 @@ - articles + articles new categories collections diff --git a/resources/views/components/tag.blade.php b/resources/views/components/tag.blade.php index fafd0b6..ade138f 100644 --- a/resources/views/components/tag.blade.php +++ b/resources/views/components/tag.blade.php @@ -1,4 +1,4 @@ -merge(['class' => str_starts_with(request()->path(), 'tags/'.$slot ) ? 'current' : '' ])}} >{{ $slot }} diff --git a/resources/views/edit.blade.php b/resources/views/edit.blade.php index f920ab3..340d25c 100644 --- a/resources/views/edit.blade.php +++ b/resources/views/edit.blade.php @@ -1,4 +1,4 @@ - +
@csrf @@ -13,4 +13,4 @@
-
+ diff --git a/resources/views/new.blade.php b/resources/views/new.blade.php index 090ab42..697c257 100644 --- a/resources/views/new.blade.php +++ b/resources/views/new.blade.php @@ -1,12 +1,12 @@ - +
@csrf - id + id title slug - + body
-
+ diff --git a/resources/views/tag.blade.php b/resources/views/tag.blade.php deleted file mode 100644 index 4057bcc..0000000 --- a/resources/views/tag.blade.php +++ /dev/null @@ -1,7 +0,0 @@ - - -
- -
- -
diff --git a/routes/web.php b/routes/web.php index 6f8e6d5..1ce552f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -36,8 +36,8 @@ Route::get('/edit/{slug}', function (string $slug) { ]); })->where('slug', '[A-Za-z0-9-]+'); -Route::get('/dashboard', function () { - return view('dashboard', [ +Route::get('/articles', function () { + return view('articles', [ 'articles' => Article::all(), ]); });