Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.
Open

L55 #48

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
270 commits
Select commit Hold shift + click to select a range
90040cc
Style landing screen, session cookie name
astroanu Jan 30, 2018
999c52b
Improve NavBar component
astroanu Jan 30, 2018
53a9ea9
Dashboard tabs styles
astroanu Jan 30, 2018
ffb45e2
Fix breadcrumb styles
astroanu Jan 30, 2018
8cdd2cd
Replace images with svg
astroanu Jan 31, 2018
05da02f
Added Terms and Batch listing
astroanu Jan 31, 2018
862ccf7
Notifications component
astroanu Feb 2, 2018
acd6697
Adde notifications for form submit handler
astroanu Feb 4, 2018
fc84eee
Added Terms create and update
astroanu Feb 5, 2018
dc1a938
Common chunk
astroanu Feb 5, 2018
03bafe9
View Terms
astroanu Feb 5, 2018
8d1e6d7
Fix unit tests for classes module
astroanu Feb 9, 2018
553d173
Added custom overrides folder
astroanu Feb 9, 2018
f28df76
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Feb 9, 2018
2ffac6e
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Feb 9, 2018
0ed9bda
Fixed bug with verifying script files
astroanu Feb 9, 2018
02ac1af
Update classes module with batches and grades CRUD
astroanu Feb 10, 2018
9332661
Pagination for lists
astroanu Feb 10, 2018
49865e6
Pagination for lists
astroanu Feb 11, 2018
9b4a571
Introducing model factories
astroanu Feb 11, 2018
dc51063
Load factories
astroanu Feb 11, 2018
ebaddc8
Renaming Menus to Menu and Modules to Module
astroanu Feb 11, 2018
d4e99b4
Refactor listDir
astroanu Feb 11, 2018
6c153cf
Classes edit and view
astroanu Feb 13, 2018
04da398
Include Helpers
astroanu Feb 14, 2018
5a57f9d
Include Helpers
astroanu Feb 14, 2018
20d41ef
Fix Laravel issue with migrations
astroanu Feb 14, 2018
bbc1fee
Apply fixes from StyleCI
astroanu Feb 14, 2018
cb837f2
Merge pull request #3 from CodeBreez/analysis-zYZBQo
astroanu Feb 14, 2018
63eece7
Update License and readme
astroanu Feb 14, 2018
19679e2
Merge remote-tracking branch 'origin/L55' into L55
astroanu Feb 14, 2018
c4b1d27
Added style ci badge
astroanu Feb 14, 2018
8d25941
Change typo
astroanu Feb 14, 2018
1c20020
Update to L5.6
astroanu Feb 14, 2018
a9d1323
Update webpack task
astroanu Feb 15, 2018
087ec8b
No need to html entities in L5.6
astroanu Feb 15, 2018
0bd369f
Update unit tests for UserRepository
astroanu Feb 16, 2018
bde2462
Apply fixes from StyleCI
astroanu Feb 16, 2018
96b9b8b
Code coverage update
astroanu Feb 16, 2018
29ba34d
Code coverage update
astroanu Feb 16, 2018
6bce420
Remove unused cover attempt
astroanu Feb 16, 2018
7642015
Classes Repository php doc
astroanu Feb 16, 2018
b5a4606
Apply fixes from StyleCI
astroanu Feb 16, 2018
451a479
Factory change params
astroanu Feb 16, 2018
9bb3a05
Merge remote-tracking branch 'origin/L55' into L55
astroanu Feb 16, 2018
4f1701f
Update Codecov
astroanu Feb 18, 2018
0db6c7c
Apply fixes from StyleCI
astroanu Feb 18, 2018
46025f5
Get user date/time
astroanu Feb 19, 2018
0f53351
Changed middleware configuration
astroanu Feb 19, 2018
2dd0628
Check installation and show landing page
astroanu Feb 19, 2018
4ffb11b
Batches and terms updates
astroanu Feb 19, 2018
cdf1e69
Apply fixes from StyleCI
astroanu Feb 19, 2018
6559eea
Batch grades
astroanu Feb 19, 2018
293a461
Merge remote-tracking branch 'origin/L55' into L55
astroanu Feb 19, 2018
9c5daf0
Seeder framework
astroanu Feb 21, 2018
22c68a2
Merge remote-tracking branch 'origin/L55' into L55
astroanu Feb 21, 2018
a521e97
Apply fixes from StyleCI
astroanu Feb 21, 2018
869a164
Install clockwork and dusk
astroanu Feb 22, 2018
679e611
Dusk
astroanu Feb 22, 2018
97f6530
Apply fixes from StyleCI
astroanu Feb 22, 2018
5265c23
Setup E2E with travis
astroanu Feb 23, 2018
6722643
Apply fixes from StyleCI
astroanu Feb 23, 2018
390986e
Run chrome headless
astroanu Feb 23, 2018
e5648e2
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Feb 23, 2018
4d2a974
Apply fixes from StyleCI
astroanu Feb 23, 2018
3fac583
Update php doc blocks
astroanu Feb 23, 2018
2655343
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Feb 23, 2018
fcbd361
Http tests for login controller
astroanu Feb 24, 2018
c7e3158
Run chrome headless
astroanu Feb 24, 2018
a052414
Migrate database before running dusk test
astroanu Feb 24, 2018
e720f63
Migrate database before running dusk test
astroanu Feb 24, 2018
5e02de0
Migrate database before running dusk test
astroanu Feb 24, 2018
c5fa1b2
Migrate database before running dusk test
astroanu Feb 24, 2018
08e4b69
Update test cases
astroanu Feb 24, 2018
ef4f371
Update test cases
astroanu Feb 24, 2018
a350e78
Added more test to menus
astroanu Feb 25, 2018
6c5ff74
Fix testcase
astroanu Feb 25, 2018
aacf34f
Removing testcase
astroanu Feb 25, 2018
ffe76dd
Removing testcase
astroanu Feb 25, 2018
bb28fb0
Apply fixes from StyleCI (#17)
astroanu Feb 26, 2018
3632114
Validator tests
astroanu Feb 25, 2018
30b13d4
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Feb 26, 2018
7e014b9
replace validator
astroanu Feb 28, 2018
81fa8e1
Criteria for batches and criteria UI
astroanu Mar 4, 2018
de235fe
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Mar 4, 2018
9b381a4
Update unit test
astroanu Mar 4, 2018
e9ad1f3
Apply fixes from StyleCI (#21)
astroanu Mar 4, 2018
9ca3f10
Actions column for batches list
astroanu Mar 4, 2018
d8fd394
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Mar 4, 2018
8ca1c18
Fixed some bugs in classes module
astroanu Mar 4, 2018
610ed28
Translate with params
astroanu Mar 5, 2018
f52d6cd
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Mar 5, 2018
67cc1d4
Removing the lang files from webpack and adding the AssetsController
astroanu Mar 5, 2018
0ece5c4
Removing trans command
astroanu Mar 5, 2018
6abdbde
Apply fixes from StyleCI (#25)
astroanu Mar 5, 2018
fb03a08
Update readme
astroanu Mar 5, 2018
54fc0fb
View batch grades
astroanu Mar 5, 2018
c2c2d29
Save terms
astroanu Mar 5, 2018
5f002ad
Added users menu
astroanu Mar 5, 2018
f22ef94
Codacy changes
astroanu Mar 6, 2018
79f3962
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Mar 6, 2018
75053c0
Update doc comment
astroanu Mar 6, 2018
01986a1
Update doc comment
astroanu Mar 6, 2018
2d3c9ae
Set correct header
astroanu Mar 6, 2018
2a1ba59
Edit classes
astroanu Mar 6, 2018
96e0069
Apply fixes from StyleCI (#30)
astroanu Mar 7, 2018
05524e4
View class details
astroanu Mar 8, 2018
7ba223f
Apply fixes from StyleCI (#36)
astroanu Mar 8, 2018
f5a413a
Remove sorting of table columns
astroanu Mar 9, 2018
e5ca691
Added users list view
astroanu Mar 9, 2018
7cffc4d
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Apr 1, 2018
35a7952
Fix seeder with terms
astroanu Apr 1, 2018
7ecf49d
Users manage and details
astroanu Apr 1, 2018
0ea3d01
Apply fixes from StyleCI (#37)
astroanu Apr 1, 2018
1df6435
Removed routes from webpack and added to assets path
astroanu Apr 6, 2018
bb19574
Apply fixes from StyleCI (#38)
astroanu Apr 6, 2018
7c54f3f
Update tests for AssetController
astroanu Apr 6, 2018
ae0d000
Apply fixes from StyleCI (#39)
astroanu Apr 6, 2018
de3c4c2
Update tests for Menus
astroanu Apr 6, 2018
551d724
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Apr 6, 2018
4d883ca
Apply fixes from StyleCI (#40)
astroanu Apr 6, 2018
d59e33c
Fix bug with alerts for ajax
astroanu Apr 9, 2018
d2dec7f
Added profile controller
astroanu Apr 9, 2018
f36bbdc
Fixed separators for nav bar
astroanu Apr 9, 2018
a5d6b10
Request classes for Batches module
astroanu Apr 9, 2018
151d8f8
Add and edit users
astroanu Apr 11, 2018
89dbe3c
Apply fixes from StyleCI (#42)
astroanu Apr 11, 2018
f23061d
ACL controller tests
astroanu Apr 13, 2018
fa085d9
Merge remote-tracking branch 'origin/L55' into L55
astroanu Apr 13, 2018
28b9f1c
Apply fixes from StyleCI (#43)
astroanu Apr 13, 2018
dd0e57d
Form helper with validation support
astroanu Apr 16, 2018
a3d055b
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Apr 16, 2018
44c64f6
Fix menu test
astroanu Apr 17, 2018
9907ca9
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Apr 17, 2018
7121cce
Apply fixes from StyleCI (#44)
astroanu Apr 17, 2018
1130064
Fix controller test
astroanu Apr 20, 2018
945b797
Apply fixes from StyleCI (#45)
astroanu Apr 20, 2018
16e746f
Fix abilityies for tests
astroanu Apr 20, 2018
39446c1
Merge remote-tracking branch 'origin/L55' into L55
astroanu Apr 20, 2018
aa33edc
Fix abilityies for tests
astroanu Apr 20, 2018
9385c23
Validatable form input component
astroanu Oct 1, 2018
45a3594
Validatable form input component
astroanu Oct 2, 2018
64b449d
Batch details validation
astroanu Oct 2, 2018
5ae023f
Edit terms
astroanu Oct 4, 2018
dd75fc7
Apply fixes from StyleCI (#46)
astroanu Oct 4, 2018
fa5e92c
Validation for grades and classes
astroanu Oct 5, 2018
dc9f6aa
User details validation
astroanu Oct 5, 2018
29d7c10
User roles edit
astroanu Oct 5, 2018
a1105f3
Apply fixes from StyleCI (#47)
astroanu Oct 5, 2018
6d78afa
User details bugs
astroanu Oct 5, 2018
aec24fb
Setup screen update
astroanu Oct 12, 2018
c183d34
Update input components and pagination helper
astroanu Oct 12, 2018
b9a8133
Filter styles
astroanu Oct 12, 2018
eddf6b2
Merge remote-tracking branch 'origin/L55' into L55
astroanu Oct 12, 2018
16a973e
Apply fixes from StyleCI (#49)
astroanu Oct 12, 2018
9a9e845
Update class modules tests
astroanu Oct 13, 2018
80af7b0
Added Students module
astroanu Oct 13, 2018
7203867
Merge remote-tracking branch 'origin/L55' into L55
astroanu Oct 13, 2018
10ebb49
Apply fixes from StyleCI (#50)
astroanu Oct 13, 2018
b2b3695
Fix some tests
astroanu Oct 14, 2018
3bcc81a
Apply fixes from StyleCI (#51)
astroanu Oct 14, 2018
9b420dc
Student module functionality, update acl module to reflect the changes
astroanu Oct 14, 2018
9bd16ad
Merge remote-tracking branch 'origin/L55' into L55
astroanu Oct 14, 2018
1301e3b
Apply fixes from StyleCI (#52)
astroanu Oct 14, 2018
3fa5822
Fix last separator on menus
astroanu Oct 14, 2018
fe94be4
Update tests
astroanu Oct 15, 2018
84eafba
Menus update
astroanu Oct 15, 2018
ed90391
Merge remote-tracking branch 'origin/L55' into L55
astroanu Oct 15, 2018
01f6ea4
Apply fixes from StyleCI (#53)
astroanu Oct 15, 2018
1e277d4
Update UserRepositoryAdminTest.php
astroanu Oct 16, 2018
fbb5932
Update readme.md
astroanu Oct 16, 2018
8ceb68e
Update profile controller and added more student module files
astroanu Oct 16, 2018
1e16197
Apply fixes from StyleCI (#54)
astroanu Oct 16, 2018
5514eed
Terms timeline
astroanu Oct 19, 2018
d1cf363
Apply fixes from StyleCI (#55)
astroanu Oct 19, 2018
bb8a60d
Terms view table
astroanu Oct 20, 2018
d7ed194
Merge remote-tracking branch 'origin/55-terms' into 55-terms
astroanu Oct 20, 2018
57885b8
TErms editor
astroanu Nov 17, 2018
ec076bb
Fix template error
astroanu Nov 17, 2018
6d417e3
Reauth flow
astroanu Nov 17, 2018
268f748
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Nov 17, 2018
78d9e34
Apply fixes from StyleCI (#57)
astroanu Nov 17, 2018
44e223a
Student categories
astroanu Nov 17, 2018
3f0a145
Merge remote-tracking branch 'origin/L55' into L55
astroanu Nov 17, 2018
70b43f2
Apply fixes from StyleCI (#58)
astroanu Nov 17, 2018
75fa7c5
Media Module init
astroanu Nov 17, 2018
71e8819
Edit student methods and views
astroanu Nov 17, 2018
4a966db
Student details and media uploader
astroanu Nov 17, 2018
f313b75
Image uploader and student details save
astroanu Nov 18, 2018
a97e198
Bug in input types
astroanu Nov 18, 2018
ce4e6c5
Code quality check
astroanu Nov 20, 2018
c440cb3
Login module bug fixes and student repo corrections
astroanu Nov 20, 2018
98b1b2c
Merge remote-tracking branch 'origin/L55' into L55
astroanu Nov 20, 2018
a96b687
Apply fixes from StyleCI (#59)
astroanu Nov 20, 2018
b189242
Fix image uploader field group
astroanu Nov 25, 2018
3162293
Introducing presenters
astroanu Apr 22, 2019
bb0f86c
Media module
astroanu Apr 22, 2019
c734ea8
Student module changes
astroanu Apr 22, 2019
9cb81c7
Reset password command
astroanu Apr 22, 2019
ec01664
User account module changes
astroanu Apr 22, 2019
3afb6e7
Main Components changes
astroanu Apr 22, 2019
39f395a
ACL module changes
astroanu Apr 22, 2019
3714700
Update submodule
astroanu Apr 22, 2019
c84c158
Apply fixes from StyleCI (#60)
astroanu Apr 22, 2019
73bf75e
Employees module created
astroanu Apr 22, 2019
1ca6bde
Fix permission
astroanu Apr 22, 2019
d427b5b
Employee model and repository
astroanu Apr 22, 2019
e0008bf
Proper error throwing for media module, and some bug fixing
astroanu Apr 24, 2019
80d2d6c
Menu item visibility
astroanu Apr 26, 2019
ba7c027
Migration changes
astroanu Apr 26, 2019
6e355fb
Column group style
astroanu Apr 26, 2019
a11018a
Permissions helper and notification for form errors
astroanu Apr 26, 2019
6da6186
Update menus
astroanu Apr 26, 2019
670df47
Remove profile controller
astroanu Apr 26, 2019
d6c7063
Role and permission update
astroanu Apr 26, 2019
d229004
User profile page
astroanu Apr 26, 2019
dcac415
Remove address
astroanu Apr 26, 2019
21c0d00
Load permissions
astroanu Apr 26, 2019
3582d70
Update students module
astroanu Apr 26, 2019
1416a18
Update exception handler
astroanu Apr 26, 2019
ed8e996
Update dashboard controller
astroanu Apr 26, 2019
0e7b1df
Update collection presenter
astroanu Apr 26, 2019
7c95dfc
Add Employee module details controller and models
astroanu Apr 26, 2019
496b019
Added has events trait
astroanu Apr 26, 2019
1619820
Update routes for employee module
astroanu Apr 26, 2019
9321590
Update employee repository
astroanu Apr 26, 2019
9c90323
Fix validation callback issue
astroanu Apr 27, 2019
f96e090
Fix menus and routes
astroanu Apr 27, 2019
1b0da42
Employee positions
astroanu Apr 27, 2019
a27ccab
Employee categories
astroanu Apr 27, 2019
2ab5b42
Fix route
astroanu Apr 27, 2019
e0c489e
Employees list
astroanu Apr 27, 2019
51866f1
Apply fixes from StyleCI (#61)
astroanu Apr 27, 2019
9b990a7
Remove terms timeline
astroanu Apr 27, 2019
18e0046
Employee grades
astroanu Apr 27, 2019
5a83bd1
Update
astroanu Apr 27, 2019
ba3c3fc
Employee departments
astroanu Apr 27, 2019
c785962
Student guardians
astroanu Apr 27, 2019
d1c4574
Apply fixes from StyleCI (#62)
astroanu Apr 27, 2019
69f5a16
Fix bugs in the employee routes
astroanu Apr 28, 2019
db17088
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu Apr 28, 2019
b7c8da5
Apply fixes from StyleCI (#63)
astroanu Apr 28, 2019
dad365f
Skeleton animation
astroanu Apr 28, 2019
6812510
Update webpack
astroanu Apr 29, 2019
6fb8593
New presenter pattern
astroanu May 19, 2019
7e7b91e
Merge branch 'L55' of github.com:CodeBreez/collejo-app into L55
astroanu May 19, 2019
fe416d7
Apply fixes from StyleCI (#64)
astroanu May 19, 2019
f91c190
Fix tests
astroanu May 20, 2019
a416390
Update test
astroanu Jul 15, 2019
46a73c9
Apply fixes from StyleCI (#65)
astroanu Jul 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
60 changes: 60 additions & 0 deletions App/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Collejo\App\Console;

use Collejo\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Console\Scheduling\Schedule;

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');

$this->registerModuleCommands();

require base_path('routes/console.php');
}

private function registerModuleCommands()
{
$modules = app()->make('modules');

foreach ($modules->getModulePaths() as $path) {
if (file_exists($path)) {
foreach (listDir($path) as $dir) {
$commandsDir = $path.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.'Commands';

$this->load($commandsDir);
}
}
}
}
}
67 changes: 67 additions & 0 deletions App/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Collejo\App\Exceptions;

use Collejo\Foundation\Exceptions\DisplayableException;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

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 = [
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
*
* @throws Exception
*
* @return mixed|void
*/
//*
public function report(Exception $exception)
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param Exception $exception
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function render($request, Exception $exception)
{
if ($exception instanceof DisplayableException && $request->expectsJson()) {
return response()->json([
'success' => false,
'data' => [],
'message' => $exception->getMessage(),
]);
}

return parent::render($request, $exception);
}
}
56 changes: 34 additions & 22 deletions src/Http/Controllers/Controller.php → App/Http/Controller.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@
<?php

namespace Collejo\App\Http\Controllers;
namespace Collejo\App\Http;

use Collejo\App\Http\JsValidator\JsValidatorFactory;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
use Collejo\App\Http\JsValidator\JsValidatorFactory;
use Request;
use JsValidate;
use Cache;
use Illuminate\Routing\Controller as BaseController;

abstract class Controller extends BaseController
class Controller extends BaseController
{
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;

use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

/**
* Prints a json response.
*
* @param bool $success
* @param array $data
* @param null $msg
*
* @return \Illuminate\Http\JsonResponse
*/
public function printJson($success = false, $data = [], $msg = null)
{
return response()->json([
'success' => $success,
'data' => $data,
'data' => $data,
'message' => $msg,
]);
}

/**
* Prints a json response that would be identified as a redirect.
*
* @param $route
* @param null $msg
*
* @return \Illuminate\Http\JsonResponse
*/
public function printRedirect($route, $msg = null)
{
return $this->printJson(true, ['redir' => $route], $msg);
}

public function printModal($view)
{
return $this->printJson(true, ['content' => $view->render()]);
}

public function printPartial($view, $msg = null, $target = null)
{
return $this->printJson(true, ['partial' => $view->render(), 'target' => Request::get('target', $target)], $msg);
}

/**
* Returns a JsValidator object from FormRequest object.
*
* @param $validatorClass
*
* @throws \Exception
*
* @return JsValidator\JsValidator
*/
public function jsValidator($validatorClass)
{
return JsValidatorFactory::create($validatorClass);
Expand Down
87 changes: 87 additions & 0 deletions App/Http/JsValidator/JsValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Collejo\App\Http\JsValidator;

class JsValidator
{
protected $rules;

protected $attributes;

public function __construct(array $rules, array $attributes)
{
$this->rules = collect($rules);
$this->attributes = collect($attributes);

$this->processRules();
}

/**
* Process rules.
*/
private function processRules()
{
$this->rules = $this->rules->map(function ($rules, $element) {
return $this->processItemRules($rules);
});
}

/**
* Renders a set of rules in the Laravel json object format.
*
* @return string
*/
public function renderRules()
{
return json_encode($this->rules);
}

/**
* Process form field rules.
*
* @param $rules
*
* @return \stdClass
*/
private function processItemRules($rules)
{
$rules = explode('|', $rules);

$returned = new \stdClass();

foreach ($rules as $rule) {
$ruleParts = explode(':', $rule);
$rule = $ruleParts[0];
$ruleOptions = isset($ruleParts[1]) ? explode(',', $ruleParts[1]) : null;
$method = 'rule'.ucfirst($rule);

switch ($rule) {
case 'max':
$returned->maxLength = intval($ruleOptions[0]);
break;

case 'min':
$returned->minLength = intval($ruleOptions[0]);
break;

case 'between':
$returned->rangeLength = [intval($ruleOptions[0]), intval($ruleOptions[1])];
break;

case 'required':
$returned->required = true;
break;

case 'email':
$returned->email = true;
break;

case 'url':
$returned->url = true;
break;
}
}

return $returned;
}
}
28 changes: 28 additions & 0 deletions App/Http/JsValidator/JsValidatorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Collejo\App\Http\JsValidator;

use Illuminate\Foundation\Http\FormRequest;

class JsValidatorFactory
{
/**
* Builds a new JsValidator from a given FormRequest class name.
*
* @param $className
*
* @throws \Exception
*
* @return JsValidator
*/
public static function create($className)
{
$class = new $className();

if (!$class instanceof FormRequest) {
throw new \Exception($className.' is not an instance of '.FormRequest::class);
}

return new JsValidator($class->rules(), $class->attributes());
}
}
Loading