restore composer.json, add mysqli extension
This commit is contained in:
50
app/Helpers/helpers.php
Executable file
50
app/Helpers/helpers.php
Executable file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Cart;
|
||||
use App\Models\PersonalAccessToken;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
|
||||
if (! function_exists('getAuthUser')) {
|
||||
function getAuthUser()
|
||||
{
|
||||
$bearer = request()->bearerToken();
|
||||
|
||||
if ($bearer) {
|
||||
[$personalAccessTokenId, $token] = explode('|', $bearer, 2);
|
||||
$personalAccessToken = PersonalAccessToken::find($personalAccessTokenId);
|
||||
|
||||
if ($personalAccessToken && hash_equals($personalAccessToken->token, hash('sha256', $token))) {
|
||||
return User::find($personalAccessToken->tokenable_id);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('getCart')) {
|
||||
function getCart($productId = null)
|
||||
{
|
||||
$user = getAuthUser();
|
||||
|
||||
if ($user) {
|
||||
$cart = Cart::where('user_id', $user->id)->get();
|
||||
} else {
|
||||
$cart = Cart::where('token', Cookie::get('cart_token'))->get();
|
||||
}
|
||||
|
||||
if ($productId) {
|
||||
return $cart->where('product_id', $productId)->first();
|
||||
}
|
||||
|
||||
return $cart;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('ceiling')) {
|
||||
function ceiling(float|int $num, $significance = 1)
|
||||
{
|
||||
return (ceil($num / $significance)) * $significance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user