mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-19 03:04:05 +00:00
Laravel 13 upgrade, updates and fixes
This commit is contained in:
22
app/Facades/Hashids.php
Normal file
22
app/Facades/Hashids.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @method static string encode(mixed ...$numbers)
|
||||
* @method static array decode(string $hash)
|
||||
* @method static string encodeHex(string $str)
|
||||
* @method static string decodeHex(string $hash)
|
||||
* @method static \Hashids\Hashids connection(string|null $name = null)
|
||||
*/
|
||||
class Hashids extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor(): string
|
||||
{
|
||||
return 'hashids';
|
||||
}
|
||||
}
|
||||
35
app/Hashids/HashidsFactory.php
Normal file
35
app/Hashids/HashidsFactory.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Hashids;
|
||||
|
||||
use Hashids\Hashids;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class HashidsFactory
|
||||
{
|
||||
public function make(array $config): Hashids
|
||||
{
|
||||
$config = $this->getConfig($config);
|
||||
|
||||
return $this->getClient($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{salt: string, length: int, alphabet: string}
|
||||
*/
|
||||
protected function getConfig(array $config): array
|
||||
{
|
||||
return [
|
||||
'salt' => Arr::get($config, 'salt', ''),
|
||||
'length' => Arr::get($config, 'length', 0),
|
||||
'alphabet' => Arr::get($config, 'alphabet', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getClient(array $config): Hashids
|
||||
{
|
||||
return new Hashids($config['salt'], $config['length'], $config['alphabet']);
|
||||
}
|
||||
}
|
||||
72
app/Hashids/HashidsManager.php
Normal file
72
app/Hashids/HashidsManager.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Hashids;
|
||||
|
||||
use Hashids\Hashids;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Resolves named Hashids clients from config/hashids.php (one "connection" per model class).
|
||||
*
|
||||
* @method string encode(mixed ...$numbers)
|
||||
* @method array decode(string $hash)
|
||||
* @method string encodeHex(string $str)
|
||||
* @method string decodeHex(string $hash)
|
||||
*/
|
||||
class HashidsManager
|
||||
{
|
||||
/**
|
||||
* @var array<string, Hashids>
|
||||
*/
|
||||
protected array $connections = [];
|
||||
|
||||
public function __construct(
|
||||
protected Repository $config,
|
||||
protected HashidsFactory $factory
|
||||
) {}
|
||||
|
||||
public function connection(?string $name = null): Hashids
|
||||
{
|
||||
$name = $name ?? $this->getDefaultConnection();
|
||||
|
||||
if (! isset($this->connections[$name])) {
|
||||
$this->connections[$name] = $this->factory->make(
|
||||
$this->getConnectionConfig($name)
|
||||
);
|
||||
}
|
||||
|
||||
return $this->connections[$name];
|
||||
}
|
||||
|
||||
public function getDefaultConnection(): string
|
||||
{
|
||||
return (string) $this->config->get('hashids.default');
|
||||
}
|
||||
|
||||
public function getFactory(): HashidsFactory
|
||||
{
|
||||
return $this->factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function getConnectionConfig(string $name): array
|
||||
{
|
||||
$connections = $this->config->get('hashids.connections', []);
|
||||
|
||||
if (! is_array($connections) || ! isset($connections[$name])) {
|
||||
throw new InvalidArgumentException("Hashids connection [{$name}] not configured.");
|
||||
}
|
||||
|
||||
return $connections[$name];
|
||||
}
|
||||
|
||||
public function __call(string $method, array $parameters): mixed
|
||||
{
|
||||
return $this->connection()->$method(...$parameters);
|
||||
}
|
||||
}
|
||||
45
app/Hashids/HashidsServiceProvider.php
Normal file
45
app/Hashids/HashidsServiceProvider.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Hashids;
|
||||
|
||||
use Hashids\Hashids as HashidsClient;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class HashidsServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton('hashids.factory', function () {
|
||||
return new HashidsFactory;
|
||||
});
|
||||
|
||||
$this->app->alias('hashids.factory', HashidsFactory::class);
|
||||
|
||||
$this->app->singleton('hashids', function (Container $app) {
|
||||
return new HashidsManager($app['config'], $app['hashids.factory']);
|
||||
});
|
||||
|
||||
$this->app->alias('hashids', HashidsManager::class);
|
||||
|
||||
$this->app->bind('hashids.connection', function (Container $app) {
|
||||
return $app['hashids']->connection();
|
||||
});
|
||||
|
||||
$this->app->alias('hashids.connection', HashidsClient::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function provides(): array
|
||||
{
|
||||
return [
|
||||
'hashids',
|
||||
'hashids.factory',
|
||||
'hashids.connection',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Company;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\CompaniesRequest;
|
||||
use App\Http\Resources\CompanyResource;
|
||||
@@ -9,7 +10,6 @@ use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Silber\Bouncer\BouncerFacade;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class CompaniesController extends Controller
|
||||
{
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Estimate;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\EstimateResource;
|
||||
use App\Models\CompanySetting;
|
||||
use App\Models\Estimate;
|
||||
use App\Services\SerialNumberFormatter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class CloneEstimateController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mail a specific invoice to the corresponding customer's email address.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(Request $request, Estimate $estimate)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Estimate;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\InvoiceResource;
|
||||
use App\Models\CompanySetting;
|
||||
@@ -10,15 +11,15 @@ use App\Models\Invoice;
|
||||
use App\Services\SerialNumberFormatter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class ConvertEstimateController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function __invoke(Request $request, Estimate $estimate, Invoice $invoice)
|
||||
{
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Invoice;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\InvoiceResource;
|
||||
use App\Models\CompanySetting;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\SerialNumberFormatter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class CloneInvoiceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mail a specific invoice to the corresponding customer's email address.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(Request $request, Invoice $invoice)
|
||||
{
|
||||
|
||||
20
app/Http/Middleware/CustomerGuest.php
Normal file
20
app/Http/Middleware/CustomerGuest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CustomerGuest
|
||||
{
|
||||
/**
|
||||
* Guest-only routes for the customer guard (same behavior as {@see CustomerRedirectIfAuthenticated}).
|
||||
*
|
||||
* @param Closure(Request): (Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ?string $guard = null): Response
|
||||
{
|
||||
return app(CustomerRedirectIfAuthenticated::class)->handle($request, $next, $guard);
|
||||
}
|
||||
}
|
||||
28
app/Http/Middleware/CustomerRedirectIfAuthenticated.php
Normal file
28
app/Http/Middleware/CustomerRedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CustomerRedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Redirect customers away from "guest" routes (e.g. login) when already authenticated.
|
||||
*
|
||||
* @param Closure(Request): (Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ?string $guard = null): Response
|
||||
{
|
||||
$guard ??= 'customer';
|
||||
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect()->to(RouteServiceProvider::CUSTOMER_HOME);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
class PreventRequestForgery extends Middleware
|
||||
{
|
||||
/**
|
||||
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
|
||||
@@ -16,7 +16,7 @@ class VerifyCsrfToken extends Middleware
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'login',
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Models\EmailLog;
|
||||
use App\Models\Estimate;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class SendEstimateMail extends Mailable
|
||||
{
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Models\EmailLog;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class SendInvoiceMail extends Mailable
|
||||
{
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Models\EmailLog;
|
||||
use App\Models\Payment;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class SendPaymentMail extends Mailable
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App;
|
||||
use App\Facades\Hashids;
|
||||
use App\Facades\PDF;
|
||||
use App\Mail\SendEstimateMail;
|
||||
use App\Services\SerialNumberFormatter;
|
||||
@@ -18,7 +19,6 @@ use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Support\Str;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class Estimate extends Model implements HasMedia
|
||||
{
|
||||
@@ -79,7 +79,7 @@ class Estimate extends Model implements HasMedia
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\EstimateItem::class);
|
||||
return $this->hasMany(EstimateItem::class);
|
||||
}
|
||||
|
||||
public function customer(): BelongsTo
|
||||
@@ -89,12 +89,12 @@ class Estimate extends Model implements HasMedia
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class, 'creator_id');
|
||||
return $this->belongsTo(User::class, 'creator_id');
|
||||
}
|
||||
|
||||
public function company(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Company::class);
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function currency(): BelongsTo
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App;
|
||||
use App\Facades\Hashids;
|
||||
use App\Facades\PDF;
|
||||
use App\Mail\SendInvoiceMail;
|
||||
use App\Services\SerialNumberFormatter;
|
||||
@@ -18,7 +19,6 @@ use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class Invoice extends Model implements HasMedia
|
||||
{
|
||||
@@ -84,7 +84,7 @@ class Invoice extends Model implements HasMedia
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\InvoiceItem::class);
|
||||
return $this->hasMany(InvoiceItem::class);
|
||||
}
|
||||
|
||||
public function taxes(): HasMany
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Jobs\GeneratePaymentPdfJob;
|
||||
use App\Mail\SendPaymentMail;
|
||||
use App\Services\SerialNumberFormatter;
|
||||
@@ -15,7 +16,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class Payment extends Model implements HasMedia
|
||||
{
|
||||
@@ -116,7 +116,7 @@ class Payment extends Model implements HasMedia
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class, 'creator_id');
|
||||
return $this->belongsTo(User::class, 'creator_id');
|
||||
}
|
||||
|
||||
public function currency(): BelongsTo
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use App\Http\Requests\RecurringInvoiceRequest;
|
||||
use App\Services\SerialNumberFormatter;
|
||||
use App\Traits\HasCustomFieldsTrait;
|
||||
@@ -11,7 +12,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class RecurringInvoice extends Model
|
||||
{
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Facades\Hashids;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class Transaction extends Model
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user