Skip to content

Commit 8a90ae4

Browse files
committed
feat: added support for routes without locale
1 parent a46c7d8 commit 8a90ae4

10 files changed

+23
-35
lines changed

src/Models/BinshopsCategoryTranslation.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22

3-
43
namespace BinshopsBlog\Models;
54

65
use Illuminate\Database\Eloquent\Model;
76

87
class BinshopsCategoryTranslation extends Model
98
{
10-
119
public $fillable = [
1210
'category_id',
1311
'category_name',
@@ -37,15 +35,16 @@ public function language()
3735
* Returns the public facing URL of showing blog posts in this category
3836
* @return string
3937
*/
40-
public function url($loacle)
38+
public function url($locale, $noLocaleRoute = false)
4139
{
4240
$theChainString = "";
4341
$cat = $this->category()->get();
4442
$chain = $cat[0]->getAncestorsAndSelf();
4543
foreach ($chain as $category){
4644
$theChainString .= "/" . $category->categoryTranslations()->where('lang_id' , $this->lang_id)->first()->slug;
4745
}
48-
return route("binshopsblog.view_category",[$loacle, $theChainString]);
46+
47+
return $noLocaleRoute ? route("binshopsblog.view_category",["", $theChainString]) : route("binshopsblog.view_category",[$locale, $theChainString]);
4948
}
5049

5150
/**

src/Models/BinshopsPostTranslation.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
namespace BinshopsBlog\Models;
54

65
use Cviebrock\EloquentSluggable\Sluggable;
@@ -199,11 +198,9 @@ protected function check_valid_image_size(string $size = 'medium')
199198
throw new \InvalidArgumentException("Invalid image size ($size). BinshopsPost image size should not begin with 'image_'. Remove this from the start of $size. It *should* be in the binshopsblog.image_sizes config though!");
200199
}
201200

202-
203201
throw new \InvalidArgumentException("BinshopsPost image size should be 'large','medium','thumbnail' or another field as defined in config/binshopsblog.php. Provided size ($size) is not valid");
204202
}
205203

206-
207204
/**
208205
*
209206
* If $this->seo_title was set, return that.
@@ -219,14 +216,15 @@ public function gen_seo_title()
219216
}
220217
return $this->title;
221218
}
219+
222220
/**
223221
* Returns the public facing URL to view this blog post
224222
*
225223
* @return string
226224
*/
227-
public function url($loacle)
225+
public function url($loacle, $noLocaleRoute = false)
228226
{
229-
return route("binshopsblog.single", [$loacle, $this->slug]);
227+
return $noLocaleRoute ? route("binshopsblog.single", ["", $this->slug]) : route("binshopsblog.single", [$loacle, $this->slug]);
230228
}
231229

232230
/**

src/Views/binshopsblog/index.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class='btn border btn-outline-primary btn-sm '>
6363
@if($categories)
6464
@include("binshopsblog::partials._category_partial", [
6565
'category_tree' => $categories,
66-
'name_chain' => $nameChain = ""
66+
'name_chain' => $nameChain = "",
67+
'noLocaleRoute' => $noLocaleRoute
6768
])
6869
@else
6970
<span>No Categories</span>

src/Views/binshopsblog/partials/_category_partial.blade.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
<li class="category-item-wrapper">
55
@php $nameChain = $nameChain .'/'. $trans->slug @endphp
66

7-
<a href="{{route("binshopsblog.view_category",[$locale, $nameChain ])}}">
7+
<a href="{{ $noLocaleRoute ? route("binshopsblog.view_category",["", $nameChain]) : route("binshopsblog.view_category",[$locale, $nameChain])}}">
88
<span class="category-item" value='{{$category->category_id}}'>
99
{{$trans->category_name}}
1010

1111
@if( count($category->siblings) > 0)
1212
<ul>
1313
@include("binshopsblog::partials._category_partial", [
1414
'category_tree' => $category->siblings,
15-
'name_chain' => $nameChain
15+
'name_chain' => $nameChain,
16+
'noLocaleRoute' => $noLocaleRoute
1617
])
1718
</ul>
1819
@endif
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class=''>
2-
@foreach($categories as $category)
3-
<a class='btn btn-outline-secondary btn-sm m-1' href='{{$category->categoryTranslations[0]->url($locale)}}'>
4-
{{$category->categoryTranslations[0]->category_name}}
5-
</a>
6-
@endforeach
2+
@foreach($categories as $category)
3+
<a class='btn btn-outline-secondary btn-sm m-1' href='{{$category->categoryTranslations[0]->url($locale, $noLocaleRoute)}}'>
4+
{{$category->categoryTranslations[0]->category_name}}
5+
</a>
6+
@endforeach
77
</div>

src/Views/binshopsblog/partials/disqus_comments.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
(d.head || d.body).appendChild(s);
1616
})();
1717
</script>
18-
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus</a>, and run by <a href='https://binshops.binshops.com/'>BinshopsBlog Laravel Blog package</a></noscript>
18+
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus</a>, and run by <a href='https://binshops.com/'>BinshopsBlog Laravel Blog package</a></noscript>

src/Views/binshopsblog/partials/index_loop.blade.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{{--Used on the index page (so shows a small summary--}}
2-
{{--See the guide on binshops.binshops.com for how to copy these files to your /resources/views/ directory--}}
3-
{{--https://binshops.binshops.com/laravel-blog-package--}}
2+
{{--See the guide on binshops.com for how to copy these files to your /resources/views/ directory--}}
43

54
<div class="col-md-6">
65
<div class="blog-item">
@@ -9,7 +8,7 @@
98
<?=$post->image_tag("medium", true, ''); ?>
109
</div>
1110
<div class="blog-inner-item">
12-
<h3 class=''><a href='{{$post->url($locale)}}'>{{$post->title}}</a></h3>
11+
<h3 class=''><a href='{{$post->url($locale, $noLocaleRoute)}}'>{{$post->title}}</a></h3>
1312
<h5 class=''>{{$post->subtitle}}</h5>
1413

1514
@if (config('binshopsblog.show_full_text_at_list'))
@@ -22,7 +21,7 @@
2221
<span class="light-text">Authored by: </span> {{$post->post->author->name}} <span class="light-text">Posted at: </span> {{date('d M Y ', strtotime($post->post->posted_at))}}
2322
</div>
2423
<div class='text-center'>
25-
<a href="{{$post->url($locale)}}" class="btn btn-primary">View Post</a>
24+
<a href="{{$post->url($locale, $noLocaleRoute)}}" class="btn btn-primary">View Post</a>
2625
</div>
2726
</div>
2827
</div>

src/Views/binshopsblog/partials/use_view_file.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{{--is logged in + canManageBinshopsBlogPosts() == true, so show a detailed error--}}
1313
<div class='alert alert-danger'>Custom blog post blade view file
1414
(<code>{{$post->full_view_file_path()}}</code>) not found. <a
15-
href='https://binshops.binshops.com/laravel/packages/help-documentation/laravel-blog-package-binshopsblog'
15+
href='https://github.com/binshops/laravel-blog'
1616
target='_blank'>See Laravel Blog Package help here</a>.
1717
</div>
1818

src/Views/binshopsblog/single_post.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</div>
1313
@endif
1414

15-
{{--https://binshops.binshops.com/laravel/packages/binshopsblog-blog-system-for-your-laravel-app/help-documentation/laravel-blog-package-binshopsblog#guide_to_views--}}
15+
{{--https://github.com/binshops/laravel-blog--}}
1616

1717
<div class='container'>
1818
<div class='row'>
@@ -40,4 +40,4 @@
4040

4141
@section('blog-custom-js')
4242
<script src="{{asset('binshops-blog.js')}}"></script>
43-
@endsection
43+
@endsection

src/routes.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@
1313

1414
Route::get('/category{subcategories}', 'BinshopsReaderController@view_category')->where('subcategories', '^[a-zA-Z0-9-_\/]+$')->name('binshopsblog.view_category');
1515

16-
// Route::get('/category/{categorySlug}',
17-
// 'BinshopsReaderController@view_category')
18-
// ->name('binshopsblog.view_category');
19-
2016
Route::get('/{blogPostSlug}',
2117
'BinshopsReaderController@viewSinglePost')
2218
->name('binshopsblog.single');
2319

24-
2520
// throttle to a max of 10 attempts in 3 minutes:
2621
Route::group(['middleware' => 'throttle:10,3'], function () {
2722
Route::post('save_comment/{blogPostSlug}',
@@ -100,10 +95,8 @@
10095

10196
Route::get("/upload", "BinshopsImageUploadController@create")->name("binshopsblog.admin.images.upload");
10297
Route::post("/upload", "BinshopsImageUploadController@store")->name("binshopsblog.admin.images.store");
103-
10498
});
10599

106-
107100
Route::delete('/delete_post/{blogPostId}',
108101
'BinshopsAdminController@destroy_post')
109102
->name('binshopsblog.admin.destroy_post');
@@ -146,10 +139,8 @@
146139
Route::delete('/delete_category/{categoryId}',
147140
'BinshopsCategoryAdminController@destroy_category')
148141
->name('binshopsblog.admin.categories.destroy_category');
149-
150142
});
151143

152-
153144
Route::group(['prefix' => 'languages'], function () {
154145

155146
Route::get('/',
@@ -170,7 +161,6 @@
170161
Route::post('/toggle_language/{languageId}',
171162
'BinshopsLanguageAdminController@toggle_language')
172163
->name('binshopsblog.admin.languages.toggle_language');
173-
174164
});
175165
});
176166
});

0 commit comments

Comments
 (0)