dym-sh/routes/web.php

99 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2024-08-06 14:12:25 +02:00
<?php
2024-08-09 10:37:35 +02:00
use App\Models\Article;
2024-08-08 11:22:35 +02:00
use App\Http\Controllers\RegisteredUserController;
2024-08-07 18:08:20 +02:00
use App\Http\Controllers\SessionController;
2024-08-06 14:12:25 +02:00
use Illuminate\Support\Facades\Route;
2024-08-09 10:37:35 +02:00
Route::get('/', function() {
return view('index', [
'greeting' => 'Hello',
'self' => 'My name is Dym Sohin, im a web-developer',
'articles' => Article::all(),
]);
});
2024-08-07 18:08:20 +02:00
Route::view('/about', 'about');
2024-08-06 16:39:08 +02:00
2024-08-07 18:08:20 +02:00
Route::view('/graphics', 'graphics');
Route::view('/photos', 'photos');
Route::view('/comics', 'comics');
Route::view('/code', 'code');
Route::view('/notes', 'notes');
2024-08-07 15:33:25 +02:00
2024-08-09 11:32:25 +02:00
Route::get('/new', function () {
return view('new');
2024-08-07 15:33:25 +02:00
});
2024-08-11 11:53:49 +02:00
Route::post('/new', function (string $title = '', string $slug = '', string $body = '') {
$article = Article::create(
[ 'title' => $title
, 'slug' => $slug
, 'body' => $body
]);
return view('edit',
[ 'article' => $article
, 'title' => $article['title']
, 'slug' => $article['slug']
, 'body' => $article['body']
]);
});
2024-08-09 11:32:25 +02:00
Route::get('/edit/{slug}', function (string $slug) {
$article = Article::find($slug);
return view('edit',
[ 'article' => $article
, 'title' => $article['title']
, 'slug' => $article['slug']
, 'body' => $article['body']
]);
2024-08-07 15:33:25 +02:00
})->where('slug', '[A-Za-z0-9-]+');
2024-08-09 11:32:25 +02:00
2024-08-11 11:53:49 +02:00
Route::post('/edit/{id}', function (string $id) {
$article = Article::findById($id);
return view('edit',
[ 'article' => $article
, 'title' => $article['title']
, 'slug' => $article['slug']
, 'body' => $article['body']
]);
})->where('id', '[0-9-]+');
2024-08-09 13:52:23 +02:00
Route::get('/articles', function () {
return view('articles', [
2024-08-09 11:32:25 +02:00
'articles' => Article::all(),
]);
2024-08-07 15:33:25 +02:00
});
2024-08-08 11:22:35 +02:00
Route::get('/register', [RegisteredUserController::class, 'create']);
Route::post('/register', [RegisteredUserController::class, 'store']);
2024-08-07 18:08:20 +02:00
Route::get('/login', [SessionController::class, 'create']);
Route::post('/login', [SessionController::class, 'store']);
Route::post('/logout', [SessionController::class, 'destroy']);
2024-08-09 11:32:25 +02:00
Route::get('/search/{search}', function (string $search) {
return view('list',
[ 'search' => $search ]
);
})->where('search', '.*');
2024-08-07 18:08:20 +02:00
2024-08-07 15:33:25 +02:00
2024-08-09 10:37:35 +02:00
Route::get('/{slug}', function (string $slug) {
$article = Article::find($slug);
return view('article',
[ 'article' => $article
, 'title' => $article['title']
, 'slug' => $article['slug']
, 'body' => $article['body']
]);
2024-08-07 15:33:25 +02:00
})->where('slug', '[A-Za-z0-9-]+');
2024-08-09 11:32:25 +02:00