Demo project
This commit is contained in:
1 parent
5e4f3540e8
commit
a68267d0f0
146 files changed
+41587
No files matched your search
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*
|
||||
* @param \App\Http\Requests\Auth\LoginRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(LoginRequest $request)
|
||||
{
|
||||
$request->authenticate();
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class ConfirmablePasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the confirm password view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
return view('auth.confirm-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (! Auth::guard('web')->validate([
|
||||
'email' => $request->user()->email,
|
||||
'password' => $request->password,
|
||||
])) {
|
||||
throw ValidationException::withMessages([
|
||||
'password' => __('auth.password'),
|
||||
]);
|
||||
}
|
||||
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationNotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Send a new email verification notification.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'verification-link-sent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
return $request->user()->hasVerifiedEmail()
|
||||
? redirect()->intended(RouteServiceProvider::HOME)
|
||||
: view('auth.verify-email');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
return view('auth.reset-password', ['request' => $request]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'token' => 'required',
|
||||
'email' => 'required|email',
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function ($user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $status == Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('auth.forgot-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'required|email',
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
// to send the link, we will examine the response then see the message we
|
||||
// need to show to the user. Finally, we'll send out a proper response.
|
||||
$status = Password::sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
return $status == Password::RESET_LINK_SENT
|
||||
? back()->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Auth\EmailVerificationRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request)
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Fruitcake\Cors\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Actual extends Component
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh'
|
||||
];
|
||||
|
||||
// General data
|
||||
public int $year;
|
||||
public array $activeMonths;
|
||||
public int $activeMonthCount;
|
||||
|
||||
// Quick add
|
||||
public string $quickValue;
|
||||
public int $quickPostID;
|
||||
public int $quickMonth;
|
||||
|
||||
// Clear month
|
||||
public string $columnName;
|
||||
public int $columnMonth;
|
||||
|
||||
// Edit field
|
||||
public string $fieldName;
|
||||
public string $fieldMonthName;
|
||||
public string $fieldTypeHTML;
|
||||
public string $fieldHistoryHTML;
|
||||
public int $fieldPostID;
|
||||
public int $fieldMonth;
|
||||
public string $fieldAddValue;
|
||||
|
||||
// Delete value
|
||||
public int $deleteValueID;
|
||||
public string $deleteValueHTML;
|
||||
|
||||
// View mode switch
|
||||
public string $switchValuesCSS;
|
||||
public string $switchDifferenceCSS;
|
||||
public string $switchMode;
|
||||
|
||||
// Modals
|
||||
public bool $modalFieldUpdate;
|
||||
public bool $modalColumnUpdate;
|
||||
public bool $modalDelete;
|
||||
|
||||
public function mount() {
|
||||
$category = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->first();
|
||||
|
||||
$this->quickValue = "";
|
||||
$this->quickPostID = $category->posts->where('year', $this->year)->count() > 0 ? $category->posts->where('year', $this->year)->first()->id : -1;
|
||||
$this->quickMonth = intval((new \Datetime())->format("m"));
|
||||
|
||||
$this->columnName = "January";
|
||||
$this->columnMonth = 1;
|
||||
|
||||
$this->fieldName = "";
|
||||
$this->fieldMonthName = $this->columnName;
|
||||
$this->fieldTypeHTML = "expense";
|
||||
$this->fieldHistoryHTML = "Nothing";
|
||||
$this->fieldPostID = $this->quickPostID;
|
||||
$this->fieldAddValue = "";
|
||||
$this->month = $this->columnMonth;
|
||||
|
||||
$this->deleteValueID = 0;
|
||||
$this->deleteValueHTML = "";
|
||||
|
||||
$this->modalFieldUpdate = false;
|
||||
$this->modalColumnUpdate = false;
|
||||
$this->modalDelete = false;
|
||||
|
||||
$this->switchMode("values");
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->activeMonths = \Auth::user()->activeActualMonths($this->year);
|
||||
$this->activeMonthCount = 0;
|
||||
foreach($this->activeMonths as $month) {
|
||||
if($month) {
|
||||
$this->activeMonthCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
|
||||
|
||||
if($this->quickPostID == -1) {
|
||||
$category = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->first();
|
||||
$this->quickPostID = $category->posts->where('year', $this->year)->count() > 0 ? $category->posts->where('year', $this->year)->first()->id : -1;
|
||||
}
|
||||
|
||||
$hf = new \App\Http\Livewire\Helper();
|
||||
|
||||
return view('livewire.actual', ["categories" => $categories, "hf" => $hf]);
|
||||
}
|
||||
|
||||
public function quickinput() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->quickPostID)->first();
|
||||
|
||||
$value = null;
|
||||
if($this->quickValue != null && trim($this->quickValue) != "" && is_numeric(trim($this->quickValue))) {
|
||||
$value = floatval($this->quickValue);
|
||||
}
|
||||
|
||||
if($value != 0) {
|
||||
$transaction = new \App\Models\TransactionValue();
|
||||
$transaction->post_id = $post->id;
|
||||
$transaction->value = $value;
|
||||
$transaction->month = $this->quickMonth;
|
||||
$transaction->save();
|
||||
}
|
||||
|
||||
$this->quickValue = "";
|
||||
$this->emit("focusField", "quickValue");
|
||||
}
|
||||
|
||||
public function openColumnUpdate($month) {
|
||||
$this->columnName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
|
||||
$this->columnMonth = $month;
|
||||
$this->modalColumnUpdate = true;
|
||||
}
|
||||
|
||||
public function closeColumnUpdate() {
|
||||
$this->modalColumnUpdate = false;
|
||||
}
|
||||
|
||||
public function updateColumn() {
|
||||
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
|
||||
foreach($categories as $category) {
|
||||
foreach($category->posts->where("year", $this->year) as $post) {
|
||||
foreach(\App\Models\TransactionValue::where("post_id", $post->id)->where("month", $this->columnMonth)->get() as $value) {
|
||||
if($value != null) {
|
||||
$value->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->modalColumnUpdate = false;
|
||||
}
|
||||
|
||||
public function openFieldUpdate($postID, $month) {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $postID)->first();
|
||||
|
||||
if($post) {
|
||||
$this->fieldPostID = $post->id;
|
||||
$this->fieldName = $post->name;
|
||||
$this->fieldTypeHTML = "<span class=\"".($post->is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income")."</span>";
|
||||
$this->fieldMonth = $month;
|
||||
$this->fieldMonthName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
|
||||
|
||||
$values = \App\Models\TransactionValue::where("post_id", $post->id)->where("month", $month);
|
||||
if($values->count() > 0) {
|
||||
$hf = new \App\Http\Livewire\Helper();
|
||||
$this->fieldHistoryHTML = "<span class=\"text-sm text-gray-500\">";
|
||||
|
||||
$first = true;
|
||||
foreach($values->get() as $value) {
|
||||
$v = $value->value * ($post->is_expense ? -1.00 : 1.00);
|
||||
|
||||
if(!$first) {
|
||||
if($value->value > 0) {
|
||||
$this->fieldHistoryHTML .= " + ";
|
||||
} else {
|
||||
$this->fieldHistoryHTML .= " - ";
|
||||
}
|
||||
} else {
|
||||
$first = false;
|
||||
}
|
||||
|
||||
$this->fieldHistoryHTML .= "<span wire:click=\"openDelete(".$value->id.")\">";
|
||||
$this->fieldHistoryHTML .= $hf->number($v);
|
||||
$this->fieldHistoryHTML .= "</span>";
|
||||
}
|
||||
|
||||
if($values->count() > 1) {
|
||||
$this->fieldHistoryHTML .= " = <strong>" . $hf->number($post->monthActualValue($month))."</strong>";
|
||||
}
|
||||
|
||||
$this->fieldHistoryHTML .= "</span>";
|
||||
} else {
|
||||
$this->fieldHistoryHTML = "<span class=\"text-sm text-gray-500\">Nothing ...</span>";
|
||||
}
|
||||
$this->modalFieldUpdate = true;
|
||||
$this->emit("focusField", "fieldAddValue");
|
||||
}
|
||||
}
|
||||
|
||||
public function closeFieldUpdate() {
|
||||
$this->modalFieldUpdate = false;
|
||||
}
|
||||
|
||||
public function addValue() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->fieldPostID)->first();
|
||||
|
||||
$value = null;
|
||||
if($this->fieldAddValue != null && trim($this->fieldAddValue) != "" && is_numeric(trim($this->fieldAddValue))) {
|
||||
$value = floatval($this->fieldAddValue);
|
||||
}
|
||||
|
||||
if($value != 0) {
|
||||
$transaction = new \App\Models\TransactionValue();
|
||||
$transaction->post_id = $post->id;
|
||||
$transaction->value = $value;
|
||||
$transaction->month = $this->fieldMonth;
|
||||
$transaction->save();
|
||||
}
|
||||
|
||||
$this->fieldAddValue = "";
|
||||
$this->openFieldUpdate($this->fieldPostID, $this->fieldMonth);
|
||||
$this->emit("focusField", "fieldAddValue");
|
||||
}
|
||||
|
||||
public function openDelete($valueID) {
|
||||
$hf = new \App\Http\Livewire\Helper();
|
||||
|
||||
$this->deleteValueID = $valueID;
|
||||
$value = \App\Models\TransactionValue::with("post")->whereHas('post', function ($query) {
|
||||
return $query->whereHas('category', function($query2) {
|
||||
return $query2->where('user_id', \Auth::user()->id);
|
||||
});
|
||||
})->where("id", $this->deleteValueID)->first();
|
||||
|
||||
$this->deleteValueHTML = $hf->number($value->value * ($value->post->is_expense ? -1.0 : 1.0));
|
||||
|
||||
$this->modalFieldUpdate = false;
|
||||
$this->modalDelete = true;
|
||||
}
|
||||
|
||||
public function closeDelete() {
|
||||
$this->modalFieldUpdate = true;
|
||||
$this->modalDelete = false;
|
||||
}
|
||||
|
||||
public function deleteValue() {
|
||||
$value = \App\Models\TransactionValue::with("post")->whereHas('post', function ($query) {
|
||||
return $query->whereHas('category', function($query2) {
|
||||
return $query2->where('user_id', \Auth::user()->id);
|
||||
});
|
||||
})->where("id", $this->deleteValueID)->first();
|
||||
|
||||
if($value != null) {
|
||||
$value->delete();
|
||||
}
|
||||
|
||||
$this->modalDelete = false;
|
||||
$this->openFieldUpdate($this->fieldPostID, $this->fieldMonth);
|
||||
}
|
||||
|
||||
public function switchMode($mode) {
|
||||
$this->switchMode = $mode;
|
||||
|
||||
if($mode == "values") {
|
||||
$this->switchValuesCSS = "bg-blue-700";
|
||||
$this->switchDifferenceCSS = "bg-gray-300";
|
||||
} else {
|
||||
$this->switchValuesCSS = "bg-gray-300";
|
||||
$this->switchDifferenceCSS = "bg-blue-700";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Categories extends Component
|
||||
{
|
||||
public $name;
|
||||
public $deleteID;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.categories', [
|
||||
'categories' => \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
if(trim($this->name) == "") {
|
||||
$this->name = ""; return;
|
||||
}
|
||||
|
||||
$existing = \App\Models\Category::where("user_id", \Auth::user()->id)->where("name", $this->name)->first();
|
||||
if($existing != null) {
|
||||
$this->name = ""; return;
|
||||
}
|
||||
|
||||
$highest = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority", "desc")->first();
|
||||
if($highest != null) {
|
||||
$highest = $highest->priority;
|
||||
} else {
|
||||
$highest = 0;
|
||||
}
|
||||
|
||||
$cat = new \App\Models\Category();
|
||||
$cat->user_id = \Auth::user()->id;
|
||||
$cat->name = trim($this->name);
|
||||
$cat->priority = $highest + 1;
|
||||
$cat->save();
|
||||
|
||||
$this->name = "";
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $this->deleteID)->first();
|
||||
if($cat) {
|
||||
$cat->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public function moveUp($catID) {
|
||||
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $catID)->first();
|
||||
if($cat) {
|
||||
$cat->move(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function moveDown($catID) {
|
||||
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $catID)->first();
|
||||
if($cat) {
|
||||
$cat->move(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
class Helper {
|
||||
public function Number($value) {
|
||||
return '<span class="'.(round($value) == 0 ? 'col-zero' : (round($value) > 0 ? 'col-pos' : 'col-neg')) .'">'.number_format(abs(round($value)), 0).'</span>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Projected extends Component
|
||||
{
|
||||
// General data
|
||||
public int $year;
|
||||
public array $activeMonths;
|
||||
public int $activeMonthCount;
|
||||
|
||||
// Creating posts
|
||||
public string $createName;
|
||||
public string $createType;
|
||||
public int $createCategoryID;
|
||||
|
||||
// Updating rows
|
||||
public string $rowName;
|
||||
public string $rowTypeHTML;
|
||||
public string $rowValue;
|
||||
public int $rowPostID;
|
||||
|
||||
// Updating fields
|
||||
public string $fieldName;
|
||||
public string $fieldTypeHTML;
|
||||
public int $fieldMonth;
|
||||
public string $fieldMonthName;
|
||||
public string $fieldValue;
|
||||
public int $fieldPostID;
|
||||
|
||||
// Update column
|
||||
public string $columnName;
|
||||
public int $columnMonth;
|
||||
|
||||
// Delete row
|
||||
public int $deletePostID;
|
||||
public string $deleteName;
|
||||
|
||||
// Copy year
|
||||
public int $copyYear;
|
||||
public string $copyMethod;
|
||||
|
||||
// Modals
|
||||
public bool $modalRowUpdate;
|
||||
public bool $modalFieldUpdate;
|
||||
public bool $modalColumnUpdate;
|
||||
public bool $modalDelete;
|
||||
|
||||
public function mount() {
|
||||
$this->createName = "";
|
||||
$this->createType = "expense";
|
||||
$this->createCategoryID = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->first()->id;
|
||||
|
||||
$this->rowName = "";
|
||||
$this->rowTypeHTML = "expense";
|
||||
$this->rowValue = "";
|
||||
$this->rowPostID = 0;
|
||||
|
||||
$this->fieldName = "";
|
||||
$this->fieldTypeHTML = "expense";
|
||||
$this->fieldMonth = 1;
|
||||
$this->fieldMonthName = "January";
|
||||
$this->fieldValue = "";
|
||||
$this->fieldPostID = 0;
|
||||
|
||||
$this->columnName = "January";
|
||||
$this->columnMonth = 1;
|
||||
|
||||
$this->deletePostID = 0;
|
||||
$this->deleteName = "";
|
||||
|
||||
$this->modalRowUpdate = false;
|
||||
$this->modalFieldUpdate = false;
|
||||
$this->modalColumnUpdate = false;
|
||||
$this->modalDelete = false;
|
||||
|
||||
$this->copyYear = 0;
|
||||
$this->copyMethod = "full";
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->activeMonths = \Auth::user()->activeMonths($this->year);
|
||||
$this->activeMonthCount = 0;
|
||||
foreach($this->activeMonths as $month) {
|
||||
if($month) {
|
||||
$this->activeMonthCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$categories = \App\Models\Category::with(["posts" => function($query) {
|
||||
$query->where("year", $this->year);
|
||||
}])->where("user_id", \Auth::user()->id)->orderBy("priority")->get();
|
||||
|
||||
$yearList = [];
|
||||
if(!\Auth::user()->hasPosts($this->year)) {
|
||||
$results = \DB::select(
|
||||
\DB::raw("SELECT DISTINCT posts.year
|
||||
FROM posts
|
||||
INNER JOIN categories ON posts.category_id = categories.id
|
||||
WHERE
|
||||
categories.user_id = :user_id
|
||||
ORDER BY posts.year DESC"),
|
||||
array('user_id' => \Auth::user()->id));
|
||||
foreach($results as $result) {
|
||||
if($this->copyYear == 0) {
|
||||
$this->copyYear = $result->year;
|
||||
}
|
||||
$yearList[] = $result->year;
|
||||
}
|
||||
}
|
||||
|
||||
$hf = new \App\Http\Livewire\Helper();
|
||||
|
||||
return view('livewire.projected', ['categories' => $categories, 'yearList' => $yearList, 'hf' => $hf]);
|
||||
}
|
||||
|
||||
public function openDelete() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->rowPostID)->first();
|
||||
|
||||
if($post) {
|
||||
$this->deletePostID = $post->id;
|
||||
$this->deleteName = $post->name;
|
||||
$this->modalDelete = true;
|
||||
$this->modalRowUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function deletePost() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->deletePostID)->first();
|
||||
|
||||
if($post) {
|
||||
$post->delete();
|
||||
$this->emitTo('actual', '$refresh');
|
||||
}
|
||||
$this->modalDelete = false;
|
||||
}
|
||||
|
||||
public function closeDelete() {
|
||||
$this->modalDelete = false;
|
||||
}
|
||||
|
||||
public function openColumnUpdate($month) {
|
||||
$this->columnName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
|
||||
$this->columnMonth = $month;
|
||||
$this->modalColumnUpdate = true;
|
||||
}
|
||||
|
||||
public function updateColumn() {
|
||||
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
|
||||
foreach($categories as $category) {
|
||||
foreach($category->posts->where("year", $this->year) as $post) {
|
||||
$value = \App\Models\PostValue::where("post_id", $post->id)->where("month", $this->columnMonth)->first();
|
||||
if($value != null) {
|
||||
$value->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->emitTo('actual', '$refresh');
|
||||
$this->modalColumnUpdate = false;
|
||||
}
|
||||
|
||||
public function closeColumnUpdate() {
|
||||
$this->modalColumnUpdate = false;
|
||||
}
|
||||
|
||||
public function openFieldUpdate($id, $month) {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $id)->first();
|
||||
|
||||
if($post) {
|
||||
$this->fieldPostID = $post->id;
|
||||
$this->fieldName = $post->name;
|
||||
$this->fieldTypeHTML = "<span class=\"".($post->is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income")."</span>";
|
||||
$this->fieldMonth = $month;
|
||||
$this->fieldMonthName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
|
||||
$this->fieldValue = $post->monthValue($month) * ($post->is_expense ? -1.00 : 1.00);
|
||||
if($this->fieldValue == "-0") {
|
||||
$this->fieldValue = "0";
|
||||
}
|
||||
$this->modalFieldUpdate = true;
|
||||
$this->emit("focusField", "fieldValue");
|
||||
}
|
||||
}
|
||||
|
||||
public function updateField() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->fieldPostID)->first();
|
||||
|
||||
$value = null;
|
||||
if($this->fieldValue != null && trim($this->fieldValue) != "" && is_numeric(trim($this->fieldValue))) {
|
||||
$value = floatval($this->fieldValue);
|
||||
}
|
||||
|
||||
if($post != null && $value !== null) {
|
||||
$post->setMonthValue($this->fieldMonth, $value);
|
||||
}
|
||||
$this->emitTo('actual', '$refresh');
|
||||
$this->modalFieldUpdate = false;
|
||||
}
|
||||
|
||||
public function closeFieldUpdate() {
|
||||
$this->modalFieldUpdate = false;
|
||||
}
|
||||
|
||||
public function openRowUpdate($id) {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $id)->first();
|
||||
|
||||
if($post) {
|
||||
$this->rowPostID = $post->id;
|
||||
$this->rowName = $post->name;
|
||||
$this->rowTypeHTML = "<span class=\"".($post->is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income")."</span>";
|
||||
$this->modalRowUpdate = true;
|
||||
$this->emit("focusField", "rowValue");
|
||||
}
|
||||
}
|
||||
|
||||
public function updateRow() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->rowPostID)->first();
|
||||
|
||||
$value = null;
|
||||
if($this->rowValue != null && trim($this->rowValue) != "" && is_numeric(trim($this->rowValue))) {
|
||||
$value = floatval($this->rowValue);
|
||||
}
|
||||
|
||||
if($post != null && $value !== null) {
|
||||
for($m=1;$m<=12;$m++) {
|
||||
$post->setMonthValue($m, $value);
|
||||
}
|
||||
}
|
||||
$this->emitTo('actual', '$refresh');
|
||||
$this->rowValue = "";
|
||||
$this->modalRowUpdate = false;
|
||||
}
|
||||
|
||||
public function closeRowUpdate() {
|
||||
$this->modalRowUpdate = false;
|
||||
}
|
||||
|
||||
public function createPost() {
|
||||
if(trim($this->createName) == "") {
|
||||
$this->createName = ""; return;
|
||||
}
|
||||
|
||||
$category = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $this->createCategoryID)->first();
|
||||
if($category == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$expense = $this->createType != "income";
|
||||
|
||||
$post = new \App\Models\Post();
|
||||
$post->year = $this->year;
|
||||
$post->name = trim($this->createName);
|
||||
$post->is_expense = $expense;
|
||||
$post->category_id = $this->createCategoryID;
|
||||
$post->save();
|
||||
|
||||
$this->createName = "";
|
||||
$this->emitTo('actual', '$refresh');
|
||||
$this->emit("focusField", "createName");
|
||||
}
|
||||
|
||||
public function copyBudget() {
|
||||
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
|
||||
foreach($categories as $category) {
|
||||
foreach($category->posts->where("year", $this->copyYear) as $post) {
|
||||
$newPost = new \App\Models\Post();
|
||||
$newPost->category_id = $category->id;
|
||||
$newPost->year = $this->year;
|
||||
$newPost->name = $post->name;
|
||||
$newPost->is_expense = $post->is_expense;
|
||||
$newPost->save();
|
||||
|
||||
if($this->copyMethod == "full") {
|
||||
for($m=1; $m <= 12; $m++) {
|
||||
$newPost->setMonthValue($m, $post->monthValue($m) * ($newPost->is_expense ? -1.00 : 1.00));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->emitTo('actual', '$refresh');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return route('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null ...$guards
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$guards)
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hosts()
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => 'required|string|email',
|
||||
'password' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the request's credentials.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
$this->ensureIsNotRateLimited();
|
||||
|
||||
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('auth.failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the login request is not rate limited.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function ensureIsNotRateLimited()
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event(new Lockout($this));
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.throttle', [
|
||||
'seconds' => $seconds,
|
||||
'minutes' => ceil($seconds / 60),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rate limiting throttle key for the request.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function throttleKey()
|
||||
{
|
||||
return Str::lower($this->input('email')).'|'.$this->ip();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
static $CACHED_VALUES = [];
|
||||
static $CACHED_ACTUAL = [];
|
||||
|
||||
public function posts() {
|
||||
return $this->hasMany(\App\Models\Post::class);
|
||||
}
|
||||
|
||||
public function move($moveUp = true) {
|
||||
$replaces = self::where("user_id", $this->user_id);
|
||||
|
||||
if($moveUp) {
|
||||
$replaces = $replaces->where("priority", "<", $this->priority)->orderBy("priority", "desc")->first();
|
||||
} else {
|
||||
$replaces = $replaces->where("priority", ">", $this->priority)->orderBy("priority", "asc")->first();
|
||||
}
|
||||
|
||||
if($replaces) {
|
||||
$tmp = $this->priority;
|
||||
$this->priority = $replaces->priority;
|
||||
$replaces->priority = $tmp;
|
||||
|
||||
$this->save();
|
||||
$replaces->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
foreach($this->posts as $post) {
|
||||
$post->delete();
|
||||
}
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
public static function ValueFromCache($id, $year, $month) {
|
||||
if(isset(Category::$CACHED_VALUES[$id])) {
|
||||
if(isset(Category::$CACHED_VALUES[$id][$year])) {
|
||||
if(isset(Category::$CACHED_VALUES[$id][$year][$month])) {
|
||||
return Category::$CACHED_VALUES[$id][$year][$month];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function SetValueInCache($id, $year, $month, $value) {
|
||||
if(!isset(Category::$CACHED_VALUES[$id])) {
|
||||
Category::$CACHED_VALUES[$id] = [];
|
||||
}
|
||||
if(!isset(Category::$CACHED_VALUES[$id][$year])) {
|
||||
Category::$CACHED_VALUES[$id][$year] = [];
|
||||
}
|
||||
Category::$CACHED_VALUES[$id][$year][$month] = $value;
|
||||
}
|
||||
|
||||
public function monthValue($year, $month) {
|
||||
$value = Category::ValueFromCache($this->id, $year, $month);
|
||||
if($value !== null) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$value = 0;
|
||||
foreach($this->posts->where("year", $year) as $post) {
|
||||
$value += $post->monthValue($month);
|
||||
}
|
||||
|
||||
Category::SetValueInCache($this->id, $year, $month, $value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function totalValue($year) {
|
||||
$value = 0;
|
||||
for($i=1;$i<=12;$i++) {
|
||||
$value += $this->monthValue($year, $i);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function avgValue($year, $count) {
|
||||
if($count == 0) { return 0; }
|
||||
return $this->totalValue($year) / $count;
|
||||
}
|
||||
|
||||
|
||||
public static function ActualFromCache($id, $year, $month) {
|
||||
if(isset(Category::$CACHED_ACTUAL[$id])) {
|
||||
if(isset(Category::$CACHED_ACTUAL[$id][$year])) {
|
||||
if(isset(Category::$CACHED_ACTUAL[$id][$year][$month])) {
|
||||
return Category::$CACHED_ACTUAL[$id][$year][$month];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function SetActualInCache($id, $year, $month, $value) {
|
||||
if(!isset(Category::$CACHED_ACTUAL[$id])) {
|
||||
Category::$CACHED_ACTUAL[$id] = [];
|
||||
}
|
||||
if(!isset(Category::$CACHED_ACTUAL[$id][$year])) {
|
||||
Category::$CACHED_ACTUAL[$id][$year] = [];
|
||||
}
|
||||
Category::$CACHED_ACTUAL[$id][$year][$month] = $value;
|
||||
}
|
||||
|
||||
public function monthActualValue($year, $month, $differenceMode = false) {
|
||||
$value = Category::ActualFromCache($this->id, $year, $month);
|
||||
if($value === null) {
|
||||
$value = 0;
|
||||
foreach($this->posts->where("year", $year) as $post) {
|
||||
$value += $post->monthActualValue($month);
|
||||
}
|
||||
|
||||
Category::SetActualInCache($this->id, $year, $month, $value);
|
||||
}
|
||||
|
||||
if($differenceMode) {
|
||||
if(!\Auth::user()->activeActualMonths($year)[$month-1]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$projected = $this->monthValue($year, $month);
|
||||
|
||||
return $value - $projected;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function totalActualValue($year, $differenceMode = false) {
|
||||
$value = 0;
|
||||
for($i=1;$i<=12;$i++) {
|
||||
$value += $this->monthActualValue($year, $i);
|
||||
}
|
||||
|
||||
if($differenceMode) {
|
||||
$projected = 0;
|
||||
for($m = 1; $m<=12; $m++) {
|
||||
if(\Auth::user()->activeActualMonths($year)[$m-1]) {
|
||||
$projected += $this->monthValue($year, $m);
|
||||
}
|
||||
}
|
||||
|
||||
return $value - $projected;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function avgActualValue($year, $count, $differenceMode = false) {
|
||||
if($count == 0) { return 0; }
|
||||
return $this->totalActualValue($year, $differenceMode) / $count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Post extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
private $monthValueCache = null;
|
||||
private $monthActualValueCache = null;
|
||||
|
||||
public function category() {
|
||||
return $this->belongsTo(\App\Models\Category::class);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
foreach(\App\Models\PostValue::where('post_id', $this->id)->get() as $value) {
|
||||
$value->delete();
|
||||
}
|
||||
foreach(\App\Models\TransactionValue::where('post_id', $this->id)->get() as $value) {
|
||||
$value->delete();
|
||||
}
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
public function setMonthValue($month, $value) {
|
||||
$postValue = \App\Models\PostValue::where("post_id", $this->id)->where("month", $month)->first();
|
||||
if($value != 0.00) {
|
||||
if($postValue == null) {
|
||||
$postValue = new \App\Models\PostValue();
|
||||
$postValue->post_id = $this->id;
|
||||
$postValue->month = $month;
|
||||
}
|
||||
$postValue->value = $value;
|
||||
$postValue->save();
|
||||
} else if($postValue != null) {
|
||||
$postValue->delete();
|
||||
}
|
||||
}
|
||||
|
||||
private function updateMonthValueCache() {
|
||||
$this->monthValueCache = [0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0 ,0];
|
||||
foreach(\App\Models\PostValue::where("post_id", $this->id)->get() as $value) {
|
||||
$this->monthValueCache[$value->month-1] = $value->value * ($this->is_expense ? -1.00 : 1.00);
|
||||
}
|
||||
}
|
||||
|
||||
public function monthValue($month) {
|
||||
if($this->monthValueCache == null) {
|
||||
$this->updateMonthValueCache();
|
||||
}
|
||||
return $this->monthValueCache[$month-1];
|
||||
}
|
||||
|
||||
public function totalValue() {
|
||||
$value = 0;
|
||||
for($i=1;$i<=12;$i++) {
|
||||
$value += $this->monthValue($i);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function avgValue($count) {
|
||||
if($count == 0) { return 0; }
|
||||
return $this->totalValue() / $count;
|
||||
}
|
||||
|
||||
private function updateMonthActualValueCache() {
|
||||
$this->monthActualValueCache = [0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0 ,0];
|
||||
foreach(\App\Models\TransactionValue::where("post_id", $this->id)->get() as $value) {
|
||||
$this->monthActualValueCache[$value->month-1] += $value->value * ($this->is_expense ? -1.00 : 1.00);
|
||||
}
|
||||
}
|
||||
|
||||
public function monthActualValue($month, $differenceMode = false) {
|
||||
if($this->monthActualValueCache == null) {
|
||||
$this->updateMonthActualValueCache();
|
||||
}
|
||||
|
||||
if($differenceMode) {
|
||||
if(!\Auth::user()->activeActualMonths($this->year)[$month-1]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$actual = $this->monthActualValueCache[$month-1];
|
||||
$projected = $this->monthValue($month);
|
||||
|
||||
return $actual - $projected;
|
||||
} else {
|
||||
return $this->monthActualValueCache[$month-1];
|
||||
}
|
||||
}
|
||||
|
||||
public function totalActualValue($differenceMode = false) {
|
||||
$value = 0;
|
||||
for($i=1;$i<=12;$i++) {
|
||||
$value += $this->monthActualValue($i);
|
||||
}
|
||||
|
||||
if($differenceMode) {
|
||||
$projected = 0;
|
||||
for($m = 1; $m<=12; $m++) {
|
||||
if(\Auth::user()->activeActualMonths($this->year)[$m-1]) {
|
||||
$projected += $this->monthValue($m);
|
||||
}
|
||||
}
|
||||
|
||||
return $value - $projected;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function avgActualValue($count, $differenceMode = false) {
|
||||
if($count == 0) { return 0; }
|
||||
|
||||
return $this->totalActualValue($differenceMode) / $count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PostValue extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function post() {
|
||||
return $this->belongsTo(\App\Models\Post::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TransactionValue extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function post() {
|
||||
return $this->belongsTo(\App\Models\Post::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
static $ACTUAL_MONTH_CACHE = null;
|
||||
|
||||
public function hasPosts($year) {
|
||||
return \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("year", $year)->count() > 0;
|
||||
}
|
||||
|
||||
public function monthValue($categories, $year, $month) {
|
||||
$value = 0;
|
||||
foreach($categories as $category) {
|
||||
$value += $category->monthValue($year, $month);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function totalValue($categories, $year) {
|
||||
$value = 0;
|
||||
foreach($categories as $category) {
|
||||
$value += $category->totalValue($year);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function avgValue($categories, $year, $count) {
|
||||
if($count == 0) { return 0; }
|
||||
return $this->totalValue($categories, $year) / $count;
|
||||
}
|
||||
|
||||
public function activeMonths($year) {
|
||||
$months = [false, false, false, false, false, false, false, false, false, false, false, false];
|
||||
|
||||
foreach(\App\Models\Category::where('user_id', $this->id)->get() as $category) {
|
||||
foreach($category->posts->where("year", $year) as $post) {
|
||||
for($i = 0; $i < 12; $i++) {
|
||||
if($months[$i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($post->monthValue($i+1) != 0) {
|
||||
$months[$i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $months;
|
||||
}
|
||||
|
||||
public function monthActualValue($categories, $year, $month, $differenceMode = false) {
|
||||
$value = 0;
|
||||
foreach($categories as $category) {
|
||||
$value += $category->monthActualValue($year, $month);
|
||||
}
|
||||
|
||||
if($differenceMode) {
|
||||
if(!$this->activeActualMonths($year)[$month-1]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$projected = $this->monthValue($categories, $year, $month);
|
||||
|
||||
return $value - $projected;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function totalActualValue($categories, $year, $differenceMode = false) {
|
||||
$value = 0;
|
||||
foreach($categories as $category) {
|
||||
$value += $category->totalActualValue($year);
|
||||
}
|
||||
|
||||
if($differenceMode) {
|
||||
$projected = 0;
|
||||
for($m = 1; $m<=12; $m++) {
|
||||
if(\Auth::user()->activeActualMonths($this->year)[$m-1]) {
|
||||
$projected += $this->monthValue($categories, $year, $m);
|
||||
}
|
||||
}
|
||||
|
||||
return $value - $projected;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function avgActualValue($categories, $year, $count, $differenceMode = false) {
|
||||
if($count == 0) { return 0; }
|
||||
return $this->totalActualValue($categories, $year, $differenceMode) / $count;
|
||||
}
|
||||
|
||||
public function activeActualMonths($year) {
|
||||
if(self::$ACTUAL_MONTH_CACHE === null) {
|
||||
self::$ACTUAL_MONTH_CACHE = [false, false, false, false, false, false, false, false, false, false, false, false];
|
||||
|
||||
foreach(\App\Models\Category::where('user_id', $this->id)->get() as $category) {
|
||||
foreach($category->posts->where("year", $year) as $post) {
|
||||
for($i = 0; $i < 12; $i++) {
|
||||
if(self::$ACTUAL_MONTH_CACHE[$i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($post->monthActualValue($i+1) != 0) {
|
||||
self::$ACTUAL_MONTH_CACHE[$i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self::$ACTUAL_MONTH_CACHE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// if(env('APP_DEBUG')) {
|
||||
// \DB::listen(function($query) {
|
||||
// \File::append(
|
||||
// storage_path('/logs/query.log'),
|
||||
// $query->sql . ' [' . implode(', ', $query->bindings) . ']' . PHP_EOL
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -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 policy mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $policies = [
|
||||
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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 listener mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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.
|
||||
*
|
||||
* This is used by Laravel authentication to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/dashboard';
|
||||
|
||||
/**
|
||||
* The controller namespace for the application.
|
||||
*
|
||||
* When present, controller route declarations will automatically be prefixed with this namespace.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
// protected $namespace = 'App\\Http\\Controllers';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
$this->routes(function () {
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
->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(optional($request->user())->id ?: $request->ip());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class AppLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('layouts.app');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class GuestLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('layouts.guest');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user