first commit

This commit is contained in:
benjibennn
2023-12-22 12:35:55 +08:00
commit 9f89a732d6
872 changed files with 156291 additions and 0 deletions

View File

@@ -0,0 +1,107 @@
<?php
namespace App\Providers;
use App\Models\Company;
// use App\Models\RelationshipUserCompany;
use App\Models\User;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
if ($this->app->environment() == 'production') {
$this->app['request']->server->set('HTTPS', true);
}
$this->setSchemaDefaultLength();
Validator::extend('base64image', function ($attribute, $value, $parameters, $validator) {
$explode = explode(',', $value);
$allow = ['png', 'jpg', 'svg', 'jpeg'];
$format = str_replace(
[
'data:image/',
';',
'base64',
],
[
'', '', '',
],
$explode[0]
);
// check file format
if (!in_array($format, $allow)) {
return false;
}
// check base64 format
if (!preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $explode[1])) {
return false;
}
return true;
});
view()->composer('partials.language_switcher', function ($view) {
$view->with('current_locale', app()->getLocale());
$view->with('available_locales', config('app.available_locales'));
});
View::composer(['theme::user.layouts.app'], function ($view) {
if (auth()->check()) {
$current_user = auth()->user();
$current_company = Company::find($current_user->current_active_company);
// $userCompanies = RelationshipUserCompany::where('user_id', $current_user->id)->pluck('company_id')->all();
// $companies = Company::findMany($userCompanies);
$view->with([
// 'companies' => $companies,
// 'userCompanies' => $userCompanies,
'current_company' => $current_company,
]);
}
});
// View::composer(['theme::layouts.app'], function ($view) {
// if (auth()->check()) {
// $current_user = auth()->user();
// $users = User::where('role_id', '>=', '11')->where('status', 'active')->get();
// $view->with([
// 'users' => $users,
// ]);
// }
// });
}
private function setSchemaDefaultLength(): void
{
try {
Schema::defaultStringLength(191);
}
catch (\Exception $exception){}
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
* The model to policy mappings for the application.
*
* @var array<class-string, class-string>
*/
protected $policies = [
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();
require base_path('routes/channels.php');
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Providers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
// Registered::class => [
// SendEmailVerificationNotification::class,
// ],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
//
}
/**
* Determine if events and listeners should be automatically discovered.
*
* @return bool
*/
public function shouldDiscoverEvents()
{
return false;
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* Typically, users are redirected here after authentication.
*
* @var string
*/
public const USER_HOME = '/user/dashboard';
public const USER_LOGIN = '/login';
public const ADMIN_HOME = '/cms/dashboard';
public const ADMIN_LOGIN = '/cms/login';
/**
* Define your route model bindings, pattern filters, and other route configuration.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::middleware('api')
->prefix('api')
->group(base_path('routes/api.php'));
Route::middleware('web')
->group(base_path('routes/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
}
}