Skip to content

Commit

Permalink
Update the routes file
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed Oct 19, 2024
1 parent 3cd2b3d commit c2e2e1f
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions workbench/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
]);
})->name('chat.index');

Route::post('/messages', function () {
$message = Message::create(request()->validate([
Route::post('/messages', function (Request $request) {
$message = Message::create($request->validate([
'content' => ['required'],
]));

Expand All @@ -54,8 +54,8 @@
return view('posts.create');
})->name('posts.create');

Route::post('/posts', function () {
$post = Post::create(request()->validate([
Route::post('/posts', function (Request $request) {
$post = Post::create($request->validate([
'title' => ['required'],
'body' => ['required'],
]));
Expand All @@ -75,17 +75,17 @@
]);
})->name('posts.edit');

Route::put('/posts/{post}', function (Post $post) {
$post->update(request()->validate([
Route::put('/posts/{post}', function (Request $request, Post $post) {
$post->update($request->validate([
'title' => ['required'],
'body' => ['required'],
]));

return to_route('posts.show', $post);
})->name('posts.update');

Route::post('/posts/{post}/comments', function (Post $post) {
$comment = $post->comments()->create(request()->validate([
Route::post('/posts/{post}/comments', function (Request $request, Post $post) {
$comment = $post->comments()->create($request->validate([
'content' => ['required'],
]));

Expand All @@ -107,12 +107,12 @@
]);
})->name('mentions.index');

Route::post('attachments', function () {
request()->validate([
Route::post('attachments', function (Request $request) {
$request->validate([
'attachment' => ['required', 'file'],
]);

$path = request()->file('attachment')->store('trix-attachments', 'public');
$path = $request->file('attachment')->store('trix-attachments', 'public');

return [
'image_url' => route('attachments.show', $path),
Expand All @@ -136,16 +136,21 @@
})->name('attachments.show')->where('path', '.*');

Route::post('/opengraph-embeds', function (Request $request) {
$request->validate(['url' => [
'bail', 'required', 'url', function (string $attribute, mixed $value, Closure $fail) {
$ip = gethostbyname($host = parse_url($value)['host']);

// Prevent sniffing domains resolved to private IP ranges...
if ($ip === $host || filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) {
$fail(__('URL is invalid.'));
}
},
]]);
$request->validate([
'url' => [
'bail',
'required',
'url',
function (string $attribute, mixed $value, Closure $fail): void {
$ip = gethostbyname($host = parse_url($value)['host']);

// Prevent sniffing domains resolved to private IP ranges...
if ($ip === $host || filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) {
$fail(__('URL is invalid.'));
}
},
],
]);

if ($opengraph = OpengraphEmbed::createFromUrl($request->url)) {
return $opengraph->toArray();
Expand Down

0 comments on commit c2e2e1f

Please sign in to comment.