added multi-lang support client

fixed rtl bootstrap file for rtl lang
WIP: need fixed for messages maybe sessions
master
A1Gard 1 month ago
parent 6d31dca0f3
commit 3bb8222120

@ -983,7 +983,7 @@ function isGuestMaxAttemptTry($action, $max = 5, $minutes = 60)
*/
function homeUrl()
{
return \route('client.welcome');
return fixUrlLang(\route('client.welcome'));
}
/**
@ -992,7 +992,7 @@ function homeUrl()
*/
function postsUrl()
{
return \route('client.posts');
return fixUrlLang(\route('client.posts'));
}
/**
* products url to best experience for multi lang shops
@ -1000,7 +1000,7 @@ function postsUrl()
*/
function productsUrl()
{
return \route('client.products');
return fixUrlLang(\route('client.products'));
}
/**
* clips url to best experience for multi lang shops
@ -1008,7 +1008,7 @@ function productsUrl()
*/
function clipsUrl()
{
return \route('client.clips');
return fixUrlLang(\route('client.clips'));
}
/**
* galleries url to best experience for multi lang shops
@ -1016,7 +1016,7 @@ function clipsUrl()
*/
function gallariesUrl()
{
return \route('client.galleries');
return fixUrlLang(\route('client.galleries'));
}
/**
* attachments url to best experience for multi lang shops
@ -1024,7 +1024,7 @@ function gallariesUrl()
*/
function attachmentsUrl()
{
return \route('client.attachments');
return fixUrlLang(\route('client.attachments'));
}
/**
@ -1033,7 +1033,7 @@ function attachmentsUrl()
*/
function tagUrl($slug)
{
return route('client.tag', $slug);
return fixUrlLang(route('client.tag', $slug));
}
function usableProp($props)
@ -1157,3 +1157,18 @@ RESULT;
}
/**
* fix url for multilang shops
* @param $url
* @return array|mixed|string|string[]
*/
function fixUrlLang($url)
{
if (app()->getLocale() != config('app.xlang.main')){
$welcome = \route('client.welcome');
return str_replace($welcome,$welcome .'/'.app()->getLocale(),$url);
}
return $url;
}

@ -15,6 +15,7 @@ use App\Models\Quantity;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;
use Plank\Metable\Meta;
use Spatie\Tags\Tag;
@ -32,9 +33,11 @@ class ClientController extends Controller
return view('client.welcome', compact('area', 'title', 'subtitle'));
}
public function post(Post $post)
public function post($slug)
{
$post = Post::where('slug', $slug)->firstOrFail();
if ($post->status = 0 && !auth()->check()) {
return abort(403);
}
@ -50,9 +53,11 @@ class ClientController extends Controller
return view('client.post', compact('area', 'post', 'title', 'subtitle', 'breadcrumb'));
}
public function clip(Clip $clip)
public function clip($slug)
{
$clip = Clip::where('slug', $slug)->firstOrFail();
if ($clip->status = 0 && !auth()->check()) {
return abort(403);
}
@ -66,8 +71,10 @@ class ClientController extends Controller
return view('client.default-list', compact('area', 'clip', 'title', 'subtitle', 'breadcrumb'));
}
public function gallery(Gallery $gallery)
public function gallery($slug)
{
$gallery = Gallery::where('slug', $slug)->firstOrFail();
if ($gallery->status = 0 && !auth()->check()) {
return abort(403);
}
@ -133,8 +140,10 @@ class ClientController extends Controller
return view('client.default-list', compact('area', 'attachs', 'title', 'subtitle'));
}
public function attachment(Attachment $attachment)
public function attachment($slug)
{
$attachment = Attachment::where('slug', $slug)->firstOrFail();
$area = 'attachment';
$title = $attachment->title;
$subtitle = $attachment->subtitle;
@ -221,8 +230,10 @@ class ClientController extends Controller
return view('client.group', compact('area', 'posts', 'title', 'subtitle', 'group', 'breadcrumb'));
}
public function product(Product $product)
public function product($slug)
{
$product = Product::where('slug', $slug)->firstOrFail();
if ($product->status = 0 && !auth()->check()) {
return abort(403);
}
@ -240,8 +251,9 @@ class ClientController extends Controller
return view('client.default-list', compact('area', 'product', 'title', 'subtitle', 'breadcrumb'));
}
public function category(Category $category, Request $request)
public function category($slug, Request $request)
{
$category = Category::where('slug', $slug)->firstOrFail();
$area = 'category';
$title = $category->name;
$subtitle = $category->subtitle;
@ -356,8 +368,9 @@ class ClientController extends Controller
return view('client.category', compact('area', 'products', 'title', 'subtitle', 'category', 'breadcrumb'));
}
public function attachDl(Attachment $attachment)
public function attachDl($slug)
{
$attachment = Attachment::where('slug', $slug)->firstOrFail();
$attachment->increment('downloads');
$file = (storage_path() . '/app/public/attachments/' . $attachment->file);
if (file_exists($file)) {
@ -366,8 +379,10 @@ class ClientController extends Controller
}
public function productCompareToggle(Product $product)
public function productCompareToggle($slug)
{
$product = Product::where('slug', $slug)->firstOrFail();
if (\Cookie::has('compares')) {
$compares = json_decode(\Cookie::get('compares'), true);
if (in_array($product->id, $compares)) {
@ -390,8 +405,10 @@ class ClientController extends Controller
}
}
public function ProductFavToggle(Product $product)
public function ProductFavToggle($slug)
{
$product = Product::where('slug', $slug)->firstOrFail();
if (!auth('customer')->check()) {
return errors([
__("You need to login first"),
@ -544,8 +561,50 @@ class ClientController extends Controller
}
public function sitemap(){
public function sitemap()
{
header('content-type: text/xml');
return view('website.sitemap');
}
public function lang(Request $request)
{
$uri = '/' . $request->path();
// Iterate through all the defined routes
$r = null;
$n = '';
foreach (Route::getRoutes() as $route) {
// Just check client routes
if (substr($route->getName(), 0, 7) != 'client.' || $route->getName() == 'client.welcome') {
continue;
}
$uri2 = str_replace('/', '\\/', $route->uri());
$uri2 = preg_replace('/\{[a-z]*\}/m', '.*', $uri2);
// Check if the route matches the given URI
if (preg_match('/' . $uri2 . '/', $uri)) {
$r = $route->action['controller'];
$n = $route->uri();
break;
}
}
$method = explode('@', $r)[1];
$segments = $request->segments();
$routes = explode('/',$n);
$args = [];
foreach ($routes as $i => $route) {
if ($route[0] == '{'){
$args[] = $segments[$i];
}
}
// dd($segments);
return $this->$method(...$args);
}
public function langIndex()
{
return $this->welcome();
}
}

@ -0,0 +1,45 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\URL;
class LangControl
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$segments = $request->segments();
if (strlen($segments[0]) == 2 && preg_match('/[A-Za-z]/', $segments[0])) {
app()->setLocale($segments[0]);
} else {
app()->setLocale(config('app.locale'));
}
array_shift($segments);
$url = \request()->path();
$url = str_replace(app()->getLocale(), '', $url);
// Modify the request
$newPath = '/' . implode('/', $segments);
$newUrl = $request->root() . $newPath . ($request->getQueryString() ? '?'.$request->getQueryString() : '');
$request->server->set('REQUEST_URI', $newPath);
$request->initialize(
$request->query->all(),
$request->request->all(),
$request->attributes->all(),
$request->cookies->all(),
$request->files->all(),
$request->server->all()
);
return $next($request);
}
}

@ -65,7 +65,7 @@ class Attachment extends Model
public function webUrl()
{
return route('client.attachment',$this->slug);
return fixUrlLang(route('client.attachment',$this->slug));
}
}

@ -77,7 +77,7 @@ class Category extends Model
public function webUrl()
{
return route('client.category',$this->slug);
return fixUrlLang(route('client.category',$this->slug));
}
public function products()

@ -55,7 +55,7 @@ class Clip extends Model
}
public function webUrl(){
return route('client.clip',$this->slug);
return fixUrlLang(route('client.clip',$this->slug));
}

@ -71,7 +71,7 @@ class Gallery extends Model implements HasMedia
}
public function webUrl(){
return route('client.gallery',$this->slug);
return fixUrlLang(route('client.gallery',$this->slug));
}

@ -84,7 +84,7 @@ class Group extends Model
public function webUrl()
{
return route('client.group',$this->slug);
return fixUrlLang(route('client.group',$this->slug));
}
public function published($limit = 10, $order = 'id', $dir = 'DESC')

@ -131,7 +131,7 @@ class Post extends Model implements HasMedia
// }
public function webUrl(){
return route('client.post',$this->slug);
return fixUrlLang(route('client.post',$this->slug));
}

@ -283,7 +283,7 @@ class Product extends Model implements HasMedia
public function webUrl()
{
return route('client.product',$this->slug);
return fixUrlLang(route('client.product',$this->slug));
}

@ -11,7 +11,11 @@
@yield('title')
</title>
@if(langIsRTL(config('app.locale')))
<link rel="stylesheet" href="{{asset('assets/vendor/bootstrap/dist/css/bootstrap.rtl.min.css')}}">
@else
<link rel="stylesheet" href="{{asset('assets/vendor/bootstrap/dist/css/bootstrap.min.css')}}">
@endif
<link rel="stylesheet" href="{{ route('theme.variable.css') }}">
@vite(['resources/sass/client.scss', 'resources/js/client.js'])

@ -2,8 +2,7 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ClientController;
Auth::routes(['register' => false]);
@ -359,18 +358,18 @@ Route::get('theme/variable.css',[\App\Http\Controllers\ThemeController::class,'c
Route::middleware([\App\Http\Middleware\VisitorCounter::class])
->name('client.')->group(function () {
// index
Route::get('/', [\App\Http\Controllers\ClientController::class,'welcome'])->name('welcome');
Route::get('/posts', [\App\Http\Controllers\ClientController::class,'posts'])->name('posts');
Route::get('/customer/sign-out', [\App\Http\Controllers\ClientController::class,'signOut'])->name('sign-out');
Route::post('/customer/sign-in/do', [\App\Http\Controllers\ClientController::class,'singInDo'])->name('sign-in-do');
Route::get('/customer/sign-in', [\App\Http\Controllers\ClientController::class,'signIn'])->name('sign-in');
Route::get('/customer/sign-up', [\App\Http\Controllers\ClientController::class,'signUp'])->name('sign-up');
Route::get('/customer/send/auth-code', [\App\Http\Controllers\ClientController::class,'sendSms'])->name('send-sms');
Route::get('/customer/check/auth-code', [\App\Http\Controllers\ClientController::class,'checkAuth'])->name('check-auth');
Route::get('/customer/profile', [\App\Http\Controllers\ClientController::class,'profile'])->name('profile');
Route::get('/compare', [\App\Http\Controllers\ClientController::class,'compare'])->name('compare');
Route::get('/galleries', [\App\Http\Controllers\ClientController::class,'galleries'])->name('galleries');
Route::get('/videos', [\App\Http\Controllers\ClientController::class,'clips'])->name('clips');
Route::get('/', [ClientController::class, 'welcome'])->name('welcome');
Route::get('/posts', [ClientController::class, 'posts'])->name('posts');
Route::get('/customer/sign-out', [ClientController::class, 'signOut'])->name('sign-out');
Route::post('/customer/sign-in/do', [ClientController::class, 'singInDo'])->name('sign-in-do');
Route::get('/customer/sign-in', [ClientController::class, 'signIn'])->name('sign-in');
Route::get('/customer/sign-up', [ClientController::class, 'signUp'])->name('sign-up');
Route::get('/customer/send/auth-code', [ClientController::class, 'sendSms'])->name('send-sms');
Route::get('/customer/check/auth-code', [ClientController::class, 'checkAuth'])->name('check-auth');
Route::get('/customer/profile', [ClientController::class, 'profile'])->name('profile');
Route::get('/compare', [ClientController::class, 'compare'])->name('compare');
Route::get('/galleries', [ClientController::class, 'galleries'])->name('galleries');
Route::get('/videos', [ClientController::class, 'clips'])->name('clips');
Route::post('/card/check', [\App\Http\Controllers\CardController::class, 'check'])->name('card.check');
Route::get('/card/discount/{code}', [\App\Http\Controllers\CardController::class, 'discount'])->name('card.discount');
Route::get('/card', [\App\Http\Controllers\CardController::class, 'index'])->name('card');
@ -378,28 +377,28 @@ Route::middleware([\App\Http\Middleware\VisitorCounter::class])
Route::get('/profile', [\App\Http\Controllers\CustomerController::class, 'profile'])->name('profile');
Route::post('/profile/save', [\App\Http\Controllers\CustomerController::class, 'save'])->name('profile.save');
Route::get('/invoice/{invoice}', [\App\Http\Controllers\CustomerController::class, 'invoice'])->name('invoice');
Route::get('/products', [\App\Http\Controllers\ClientController::class,'products'])->name('products');
Route::get('/attachments', [\App\Http\Controllers\ClientController::class,'attachments'])->name('attachments');
Route::get('/attachment/{attachment}', [\App\Http\Controllers\ClientController::class,'attachment'])->name('attachment');
Route::get('/tag/{slug}', [\App\Http\Controllers\ClientController::class,'tag'])->name('tag'); // wip
Route::get('/group/{slug}', [\App\Http\Controllers\ClientController::class,'group'])->name('group'); // wip
Route::get('/product/{product}', [\App\Http\Controllers\ClientController::class,'product'])->name('product');
Route::get('/video/{clip}', [\App\Http\Controllers\ClientController::class,'clip'])->name('clip');
Route::get('/category/{category}', [\App\Http\Controllers\ClientController::class,'category'])->name('category');
Route::get('/gallery/{gallery}', [\App\Http\Controllers\ClientController::class,'gallery'])->name('gallery');
Route::get('/search', [\App\Http\Controllers\ClientController::class,'search'])->name('search');
Route::get('attach/download/{attachment}', [\App\Http\Controllers\ClientController::class,'attachDl'])->name('attach-dl');
Route::get('/post/{post}', [\App\Http\Controllers\ClientController::class,'post'])->name('post');
Route::get('product/fav/toggle/{product}', [\App\Http\Controllers\ClientController::class, 'ProductFavToggle'])->name('product-fav-toggle');
Route::get('product/compare/toggle/{product}', [\App\Http\Controllers\ClientController::class, 'productCompareToggle'])->name('product-compare-toggle');
Route::get('/products', [ClientController::class, 'products'])->name('products');
Route::get('/attachments', [ClientController::class, 'attachments'])->name('attachments');
Route::get('/attachment/{attachment}', [ClientController::class, 'attachment'])->name('attachment');
Route::get('/tag/{slug}', [ClientController::class, 'tag'])->name('tag'); // wip
Route::get('/group/{slug}', [ClientController::class, 'group'])->name('group'); // wip
Route::get('/product/{product}', [ClientController::class, 'product'])->name('product');
Route::get('/video/{clip}', [ClientController::class, 'clip'])->name('clip');
Route::get('/category/{category}', [ClientController::class, 'category'])->name('category');
Route::get('/gallery/{gallery}', [ClientController::class, 'gallery'])->name('gallery');
Route::get('/search', [ClientController::class, 'search'])->name('search');
Route::get('attach/download/{attachment}', [ClientController::class, 'attachDl'])->name('attach-dl');
Route::get('/post/{post}', [ClientController::class, 'post'])->name('post');
Route::get('product/fav/toggle/{product}', [ClientController::class, 'ProductFavToggle'])->name('product-fav-toggle');
Route::get('product/compare/toggle/{product}', [ClientController::class, 'productCompareToggle'])->name('product-compare-toggle');
Route::get('card/toggle/{product}', [\App\Http\Controllers\CardController::class, 'productCardToggle'])->name('product-card-toggle');
Route::post('/comment/submit', [\App\Http\Controllers\ClientController::class,'submitComment'])->name('comment.submit');
Route::post('/comment/submit', [ClientController::class, 'submitComment'])->name('comment.submit');
});
Route::get('/sitemap.xml',[\App\Http\Controllers\ClientController::class,'sitemap'])->name('sitemap');
Route::get('/sitemap.xml', [ClientController::class, 'sitemap'])->name('sitemap');
// to developer test
Route::get('login/as/{mobile}', function ($mobile) {
@ -419,11 +418,19 @@ Route::get('test',function (){
})->name('test');
Route::get('whoami', function () {
if (!auth('customer')->check()) {
return 'You are nothing';
}
return \Auth::guard('customer')->user();
})->name('whoami');
Route::any('{lang}/{any}', [ClientController::class, 'lang'])
->where('any', '.*')
->where('lang','[A-Za-z]{2}')
->middleware([\App\Http\Middleware\LangControl::class]);
Route::any('{lang}', [ClientController::class, 'langIndex'])
->where('lang','[A-Za-z]{2}')
->middleware([\App\Http\Middleware\LangControl::class]);

Loading…
Cancel
Save