Skip to content

Commit c786c6c

Browse files
committed
feat: adds new routes to routes, and adapts DetectLanguage logic
1 parent 1a8fdae commit c786c6c

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/Middleware/DetectLanguage.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,33 @@
33

44
namespace BinshopsBlog\Middleware;
55

6+
use BinshopsBlog\Models\BinshopsConfiguration;
67
use Closure;
78
use BinshopsBlog\Models\BinshopsLanguage;
89

910
class DetectLanguage
1011
{
1112
public function handle($request, Closure $next)
1213
{
13-
$lang = BinshopsLanguage::where('locale', $request->route('locale'))
14+
$locale = $request->route('locale');
15+
$noLocaleRoute = false;
16+
17+
if (!$request->route('locale')){
18+
$noLocaleRoute = true;
19+
$locale = BinshopsConfiguration::get('DEFAULT_LANGUAGE_LOCALE');
20+
}
21+
$lang = BinshopsLanguage::where('locale', $locale)
1422
->where('active', true)
1523
->first();
1624

1725
if (!$lang){
1826
return abort(404);
1927
}
20-
$request->attributes->add(['lang_id' => $lang->id, 'locale' => $lang->locale]);
28+
$request->attributes->add([
29+
'lang_id' => $lang->id,
30+
'locale' => $lang->locale,
31+
'noLocaleRoute' => $noLocaleRoute
32+
]);
2133

2234
return $next($request);
2335
}

src/routes.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,33 @@
2424

2525
// throttle to a max of 10 attempts in 3 minutes:
2626
Route::group(['middleware' => 'throttle:10,3'], function () {
27-
2827
Route::post('save_comment/{blogPostSlug}',
2928
'BinshopsCommentWriterController@addNewComment')
3029
->name('binshopsblog.comments.add_new_comment');
30+
});
31+
});
3132

33+
Route::group(['prefix' => config('binshopsblog.blog_prefix', 'blog')], function () {
3234

33-
});
35+
Route::get('/', 'BinshopsReaderController@index')
36+
->name('binshopsblognolocale.index');
3437

35-
});
38+
Route::get('/search', 'BinshopsReaderController@search')
39+
->name('binshopsblognolocale.search');
3640

41+
Route::get('/category{subcategories}', 'BinshopsReaderController@view_category')->where('subcategories', '^[a-zA-Z0-9-_\/]+$')->name('binshopsblognolocale.view_category');
42+
43+
Route::get('/{blogPostSlug}',
44+
'BinshopsReaderController@viewSinglePost')
45+
->name('binshopsblognolocale.single');
46+
47+
// throttle to a max of 10 attempts in 3 minutes:
48+
Route::group(['middleware' => 'throttle:10,3'], function () {
49+
Route::post('save_comment/{blogPostSlug}',
50+
'BinshopsCommentWriterController@addNewComment')
51+
->name('binshopsblognolocale.comments.add_new_comment');
52+
});
53+
});
3754

3855
/* Admin backend routes - CRUD for posts, categories, and approving/deleting submitted comments */
3956
Route::group(['prefix' => config('binshopsblog.admin_prefix', 'blog_admin')], function () {

0 commit comments

Comments
 (0)