Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0507dc83d8 | ||
|
dd64cba897 | ||
|
8093eb8b72 | ||
|
af1ea1b5fd | ||
|
a4650f8710 | ||
|
4b25f97314 | ||
|
2eaf000ce0 | ||
|
1f114667aa | ||
|
f801001571 | ||
|
45be8553a2 | ||
|
9798f6aa7d |
@@ -10,9 +10,8 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"igaster/laravel-theme": "^2.0.17",
|
||||
"creativeorange/gravatar": "^1.0",
|
||||
"orchestra/asset": "^6.0"
|
||||
"creativeorange/gravatar": "^1.0",
|
||||
"orchestra/asset": "^6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
},
|
||||
@@ -27,7 +26,10 @@
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Leenooks\\Providers\\LeenooksServiceProvider"
|
||||
"Orchestra\\Asset\\AssetServiceProvider",
|
||||
"Collective\\Html\\HtmlServiceProvider",
|
||||
"Leenooks\\Providers\\LeenooksServiceProvider",
|
||||
"Leenooks\\Providers\\CustomBladeServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@@ -45,14 +45,14 @@
|
||||
<p class="login-box-msg">{{ trans('adminlte_lang::message.siginsession') }}</p>
|
||||
|
||||
<form method="post">
|
||||
{{ csrf_field() }}
|
||||
@csrf
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="input-group mb-3">
|
||||
<input type="email" name="email" class="form-control" placeholder="Email">
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text"><i class="fas fa-envelope fa-fw"></i></span>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-envelope"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -61,7 +61,7 @@
|
||||
<div class="input-group mb-3">
|
||||
<input type="password" name="password" class="form-control" placeholder="Password">
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text"><i class="fas fa-key fa-fw"></i></span>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-key"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -35,13 +35,15 @@
|
||||
<p class="login-box-msg">You forgot your password? Here you can easily retrieve a new password.</p>
|
||||
|
||||
<form method="post" action="{{ url('password/email') }}">
|
||||
{{ csrf_field() }}
|
||||
@csrf
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<input type="email" name="email" class="form-control" placeholder="Email" required>
|
||||
<div class="input-group-append">
|
||||
<span class="fas fa-envelope input-group-text"></span>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-envelope"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-primary btn-block">{{ trans('adminlte_lang::message.sendpassword') }}</button>
|
||||
|
@@ -27,32 +27,36 @@
|
||||
<p class="login-box-msg">You are only one step a way from your new password, set your new password now.</p>
|
||||
|
||||
<form method="post" action="{{ url('password/reset') }}">
|
||||
{{ csrf_field() }}
|
||||
<input type="hidden" name="token" value="{{ $token }}">
|
||||
@csrf
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<input type="email" name="email" class="form-control" placeholder="Email" required>
|
||||
<div class="input-group-append">
|
||||
<span class="fas fa-envelope fa-fw input-group-text"></span>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-envelope"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<input type="password" name="password" class="form-control" placeholder="Password" required>
|
||||
<div class="input-group-append">
|
||||
<span class="fas fa-lock input-group-text"></span>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-lock"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<input type="password" name="password_confirmation" class="form-control" placeholder="Confirm Password" data-match="#password" required>
|
||||
<div class="input-group-append">
|
||||
<span class="fas fa-lock input-group-text"></span>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-clone"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-primary btn-block">{{ trans('adminlte_lang::message.passwordreset') }}</button>
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
</div>
|
||||
<input type="hidden" name="token" value="{{ $token }}">
|
||||
</form>
|
||||
|
||||
<p class="mt-3 mb-1">
|
||||
|
@@ -46,7 +46,7 @@
|
||||
|
||||
<div class="dropdown-divider"></div>
|
||||
@if ($user->switched)
|
||||
<a href="{{ url('/admin/switch/stop') }}" class="dropdown-item" id="switch">
|
||||
<a href="{{ url('/admin/switch/stop') }}" class="dropdown-item">
|
||||
<i class="fas fa-sign-out-alt mr-2"></i> {{ trans('adminlte_lang::message.switchoff') }}
|
||||
</a>
|
||||
@else
|
||||
|
@@ -2,7 +2,7 @@
|
||||
<aside class="main-sidebar sidebar-dark-primary elevation-4 d-print-none">
|
||||
<!-- Brand Logo -->
|
||||
<a href="{{ url('home') }}" class="brand-link">
|
||||
<img src="{{ asset('img/logo.png') }}" alt="Logo" class="brand-image img-circle elevation-3" style="opacity: .8">
|
||||
<img src="{{ asset('img/logo.png') }}" alt="Logo" style="margin-left: 0; padding: 5px;" class="brand-image">
|
||||
<span class="brand-text font-weight-light">{!! config('app.name_html_long','<b>App</b>Name') !!}</span>
|
||||
</a>
|
||||
|
||||
|
@@ -6,9 +6,9 @@
|
||||
<div class="row">
|
||||
<!-- BEGIN BOTTOM ABOUT BLOCK -->
|
||||
<div class="col-md-4 col-sm-6 pre-footer-col">
|
||||
@isset($so->site_aboutus))
|
||||
@isset($site->site_aboutus))
|
||||
<h2>About us</h2>
|
||||
<p>{!! $so->site_aboutus !!}</p>
|
||||
<p>{!! $site->site_aboutus !!}</p>
|
||||
<!--
|
||||
<div class="photo-stream">
|
||||
<h2>Photos Stream</h2>
|
||||
@@ -26,11 +26,11 @@
|
||||
<h2 style="text-align: right;">Our Contact Details</h2>
|
||||
<address class="margin-bottom-40" style="float: right;">
|
||||
<table>
|
||||
<tr><th style="vertical-align:top; padding-right: 5px;">Address</th><td>{!! $so->address('html') !!}</td></tr>
|
||||
@isset($so->site_fax)
|
||||
<tr><th>Fax</th><td>{{ $so->site_fax }}</tr>
|
||||
<tr><th style="vertical-align:top; padding-right: 5px;">Address</th><td>{!! join('<br>',$site->address) !!}</td></tr>
|
||||
@isset($site->site_fax)
|
||||
<tr><th>Fax</th><td>{{ $site->site_fax }}</tr>
|
||||
@endif
|
||||
<tr><th>Email</th><td> <a href="mailto:{{ $so->site_email }}">{{ $so->site_email }}</a></tr>
|
||||
<tr><th>Email</th><td> <a href="mailto:{{ $site->site_email }}">{{ $site->site_email }}</a></tr>
|
||||
</table>
|
||||
</address>
|
||||
<!--
|
||||
@@ -81,8 +81,8 @@
|
||||
<!-- BEGIN SOCIAL -->
|
||||
<div class="col-md-4 col-sm-4">
|
||||
<ul class="social-footer list-unstyled list-inline pull-right">
|
||||
@foreach ($so->social as $social)
|
||||
<li><a href="{{ $social['url'] }}"><i class="fa fa-{{ $social['name'] }}"></i></a></li>
|
||||
@foreach ($site->social as $social)
|
||||
<li><a href="{{ $social['url'] }}"><i class="fab fa-{{ $social['name'] }}"></i></a></li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
|
@@ -23,13 +23,13 @@
|
||||
<link href="//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|PT+Sans+Narrow|Source+Sans+Pro:200,300,400,600,700,900&subset=all" rel="stylesheet" type="text/css">
|
||||
|
||||
<meta property="og:site_name" content="{{ config('app.name') }}" />
|
||||
<meta property="og:title" content="{{ $so->site_name }}" />
|
||||
<meta property="og:description" content="{{ $so->site_description }}" />
|
||||
<meta property="og:title" content="{{ $site->site_name }}" />
|
||||
<meta property="og:description" content="{{ $site->site_description }}" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:image" content="{{ $so->site_logo }}" />
|
||||
<meta property="og:image" content="{{ $site->site_logo }}" />
|
||||
<meta property="og:url" content="{{ url('/') }}" />
|
||||
|
||||
<link rel="shortcut icon" href="{{ object_get($so,'favicon','favicon.ico') }}" />
|
||||
<link rel="shortcut icon" href="{{ object_get($site,'favicon','favicon.ico') }}" />
|
||||
|
||||
<!-- Custom CSS -->
|
||||
@css('css/custom.css')
|
||||
|
@@ -5,8 +5,8 @@
|
||||
<!-- BEGIN TOP BAR LEFT PART -->
|
||||
<div class="col-md-6 col-sm-6 additional-shop-info">
|
||||
<ul class="list-unstyled list-inline">
|
||||
<li><i class="fas fa-phone mr-4"></i><span>{!! $so->site_phone !!}</span></li>
|
||||
<li><i class="fas fa-envelope mr-4"></i><span>{!! $so->site_email !!}</span></li>
|
||||
<li><i class="fas fa-phone mr-4"></i><span>{!! $site->site_phone !!}</span></li>
|
||||
<li><i class="fas fa-envelope mr-4"></i><span>{!! $site->site_email !!}</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- END TOP BAR LEFT PART -->
|
||||
@@ -29,14 +29,14 @@
|
||||
<!-- BEGIN HEADER -->
|
||||
<div class="header">
|
||||
<div class="container">
|
||||
<a class="site-logo" href="{{ url('/') }}"><img src="{{ $so->site_logo }}" alt="{{ $so->site_description }}" height="32"></a>
|
||||
<a class="site-logo" href="{{ url('/') }}"><img src="{{ $site->site_logo }}" alt="{{ $site->site_description }}" height="32"></a>
|
||||
<a href="javascript:void(0);" class="mobi-toggler"><i class="fa fa-bars"></i></a>
|
||||
|
||||
<!-- BEGIN NAVIGATION -->
|
||||
<div class="header-navigation pull-right font-transform-inherit">
|
||||
<ul>
|
||||
{{-- @todo Replace this with a function that can traverse children with multiple depths --}}
|
||||
@foreach ($so->top_menu as $item => $menu)
|
||||
@foreach ($site->top_menu as $item => $menu)
|
||||
<li class="dropdown {{ Request::is($menu['url']) ? 'active' : '' }}">
|
||||
|
||||
@if (! \Illuminate\Support\Arr::get($menu,'children'))
|
||||
|
@@ -15,15 +15,38 @@ class Carbon extends CarbonBase
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
switch (true) {
|
||||
case $name === 'half':
|
||||
switch ($name) {
|
||||
case 'half':
|
||||
return (int) ceil($this->month / static::MONTHS_PER_HALF);
|
||||
|
||||
case 'quarter_string':
|
||||
return sprintf('%dQ%d',$this->year,$this->quarter);
|
||||
|
||||
default:
|
||||
return parent::__get($name);
|
||||
}
|
||||
}
|
||||
|
||||
public function addHalf(): self
|
||||
{
|
||||
return $this->addHalves(1);
|
||||
}
|
||||
|
||||
public function addHalves(int $unit): self
|
||||
{
|
||||
return $this->addQuarters(2*$unit);
|
||||
}
|
||||
|
||||
public function subHalf(): self
|
||||
{
|
||||
return $this->subHalves(1);
|
||||
}
|
||||
|
||||
public function subHalves(int $unit): self
|
||||
{
|
||||
return $this->subQuarters(2*$unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify to the first occurrence of a given day of the week
|
||||
* in the current quarter. If no dayOfWeek is provided, modify to the
|
||||
@@ -35,7 +58,7 @@ class Carbon extends CarbonBase
|
||||
* @return static
|
||||
*/
|
||||
public function startOfHalf($dayOfWeek = null)
|
||||
{
|
||||
{
|
||||
return $this->setDate($this->year, $this->half * static::MONTHS_PER_HALF - 5, 1)->firstOfMonth($dayOfWeek);
|
||||
}
|
||||
|
||||
@@ -50,7 +73,7 @@ class Carbon extends CarbonBase
|
||||
* @return static
|
||||
*/
|
||||
public function endOfHalf($dayOfWeek = null)
|
||||
{
|
||||
{
|
||||
return $this->setDate($this->year, $this->half * static::MONTHS_PER_HALF, 1)->lastOfMonth($dayOfWeek);
|
||||
}
|
||||
}
|
||||
|
235
src/Providers/CustomBladeServiceProvider.php
Normal file
235
src/Providers/CustomBladeServiceProvider.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Orchestra\Support\Facades\Asset;
|
||||
|
||||
class CustomBladeServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Blade::directive('css',function(string $expression,array $args=[]) {
|
||||
return $this->resolve('css',$expression);
|
||||
});
|
||||
|
||||
Blade::directive('js',function($expression,string $options=NULL) {
|
||||
return $this->resolve('js',$expression);
|
||||
});
|
||||
}
|
||||
|
||||
private function resolve(string $content,string $expression): string
|
||||
{
|
||||
if (str_contains($expression,','))
|
||||
[$type,$arguments] = explode(',',$expression,2);
|
||||
|
||||
else {
|
||||
$type = $expression;
|
||||
$arguments = '';
|
||||
}
|
||||
|
||||
$arguments = explode('|',$arguments);
|
||||
|
||||
$return = collect();
|
||||
$urls = collect();
|
||||
|
||||
switch ($type) {
|
||||
case 'datatables':
|
||||
switch ($content) {
|
||||
case 'css':
|
||||
// Base
|
||||
$urls->put($type,'https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css');
|
||||
|
||||
foreach ($arguments as $option) {
|
||||
$key = $type.':'.$option;
|
||||
switch ($option) {
|
||||
case 'bootstrap4':
|
||||
$urls->put($key,'/plugin/dataTables/dataTables.bootstrap4.css');
|
||||
break;
|
||||
|
||||
case 'buttons':
|
||||
$urls->put($key,'https://cdn.datatables.net/buttons/1.6.5/css/buttons.dataTables.min.css');
|
||||
break;
|
||||
|
||||
case 'fixedheader':
|
||||
$urls->put($key,'https://cdn.datatables.net/fixedheader/3.1.7/css/fixedHeader.dataTables.min.css');
|
||||
break;
|
||||
|
||||
case 'rowgroup':
|
||||
$urls->put($key,'https://cdn.datatables.net/rowgroup/1.1.2/css/rowGroup.dataTables.min.css');
|
||||
break;
|
||||
|
||||
case 'responsive':
|
||||
$urls->put($key,'http://cdn.datatables.net/responsive/2.2.6/css/responsive.dataTables.min.css');
|
||||
break;
|
||||
|
||||
case 'searchpanes':
|
||||
$urls->put($key,'https://cdn.datatables.net/searchpanes/1.2.1/css/searchPanes.dataTables.min.css');
|
||||
break;
|
||||
|
||||
case 'searchpanes-left':
|
||||
$urls->put('searchpanes:searchpanes-left','/plugin/dataTables/leftSearchPanes.css');
|
||||
break;
|
||||
|
||||
case 'select':
|
||||
$urls->put($key,'https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css');
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$type,$content,$option));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'js':
|
||||
// Base
|
||||
$urls->put($type,'https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js');
|
||||
|
||||
foreach ($arguments as $option) {
|
||||
$key = $type.':'.$option;
|
||||
|
||||
switch ($option) {
|
||||
case 'bootstrap4':
|
||||
$urls->put($key,'/plugin/dataTables/dataTables.bootstrap4.js');
|
||||
break;
|
||||
|
||||
case 'buttons':
|
||||
$urls->put($key,'https://cdn.datatables.net/buttons/1.6.5/js/dataTables.buttons.min.js');
|
||||
$urls->put($key.'html5','https://cdn.datatables.net/buttons/1.6.5/js/buttons.html5.min.js');
|
||||
$urls->put($key.'jszip','https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.0/jszip.min.js');
|
||||
break;
|
||||
|
||||
case 'fixedheader':
|
||||
$urls->put($key,'https://cdn.datatables.net/fixedheader/3.1.7/js/dataTables.fixedHeader.min.js');
|
||||
break;
|
||||
|
||||
case 'responsive':
|
||||
$urls->put($key,'https://cdn.datatables.net/responsive/2.2.6/js/dataTables.responsive.min.js');
|
||||
break;
|
||||
|
||||
case 'rowgroup':
|
||||
$urls->put($key,'https://cdn.datatables.net/rowgroup/1.1.2/js/dataTables.rowGroup.min.js');
|
||||
break;
|
||||
|
||||
case 'searchpanes':
|
||||
$urls->put($key,'https://cdn.datatables.net/searchpanes/1.2.1/js/dataTables.searchPanes.min.js');
|
||||
break;
|
||||
|
||||
case 'select':
|
||||
$urls->put($key,'https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js');
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$type,$content,$option));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'datepick':
|
||||
switch ($content) {
|
||||
case 'css':
|
||||
$urls->put($type,'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css');
|
||||
break;
|
||||
|
||||
case 'js':
|
||||
$urls->put($type,'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js');
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'highcharts':
|
||||
switch ($content) {
|
||||
case 'js':
|
||||
// Base
|
||||
$urls->put($type,'https://code.highcharts.com/highcharts.js');
|
||||
|
||||
foreach ($arguments as $option) {
|
||||
$key = $type.':'.$option;
|
||||
switch ($option) {
|
||||
case '3d':
|
||||
$urls->put($key,'https://code.highcharts.com/highcharts-3d.js');
|
||||
$urls->put($key.'mouseover','/plugin/highcharts/3dmouseover.js');
|
||||
break;
|
||||
|
||||
case 'data':
|
||||
$urls->put($key,'https://code.highcharts.com/modules/data.js');
|
||||
break;
|
||||
|
||||
case 'defaults':
|
||||
$urls->put($key,'/plugin/highcharts/defaults.js');
|
||||
break;
|
||||
|
||||
case 'drilldown':
|
||||
$urls->put($key,'https://code.highcharts.com/modules/drilldown.js');
|
||||
break;
|
||||
|
||||
case 'heatmap':
|
||||
$urls->put($key,'https://code.highcharts.com/modules/heatmap.js');
|
||||
break;
|
||||
|
||||
case 'export':
|
||||
$urls->put($key,'https://code.highcharts.com/modules/exporting.js');
|
||||
$urls->put($key.'data','https://code.highcharts.com/modules/export-data.js');
|
||||
break;
|
||||
|
||||
case 'theme-dark':
|
||||
$urls->put($key,'https://code.highcharts.com/themes/dark-unica.js');
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$type,$content,$option));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'highcharts-stock':
|
||||
switch ($content) {
|
||||
case 'js':
|
||||
// Base
|
||||
$urls->put($type,'https://code.highcharts.com/stock/highstock.js');
|
||||
|
||||
foreach ($arguments as $option) {
|
||||
$key = $type.':'.$option;
|
||||
switch ($option) {
|
||||
case 'data':
|
||||
$urls->put($key,'https://code.highcharts.com/stock/modules/data.js');
|
||||
break;
|
||||
|
||||
case 'export':
|
||||
$urls->put($key,'https://code.highcharts.com/stock/modules/exporting.js');
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$type,$content,$option));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \Exception(sprintf('Unknown Expression: [%s]',$expression));
|
||||
}
|
||||
|
||||
if ($urls->count())
|
||||
return $urls->map(function($item,$key) {
|
||||
$dependancy='';
|
||||
if (str_contains($key,':'))
|
||||
[$dependancy,$key] = explode(':',$key);
|
||||
|
||||
return "<?php Asset::add('$key','$item','$dependancy'); ?>";
|
||||
})->join('');
|
||||
}
|
||||
}
|
@@ -10,8 +10,8 @@ trait ScopeActive
|
||||
/**
|
||||
* Only query active records
|
||||
*/
|
||||
public function scopeActive()
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $this->where('active',TRUE);
|
||||
return $query->where($this->getTable().'.active',TRUE);
|
||||
}
|
||||
}
|
||||
|
45
src/Traits/SingleOrFail.php
Normal file
45
src/Traits/SingleOrFail.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Extend Eloquent so that it includes singleOrFail calls to test that a query returns only 1 record
|
||||
*/
|
||||
namespace Leenooks\Traits;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
trait SingleOrFail
|
||||
{
|
||||
public static function bootSingleOrfail(): void
|
||||
{
|
||||
// When a query should return 1 object, or FAIL if it doesnt
|
||||
Builder::macro('singleOrFail',function () {
|
||||
$result = $this->get();
|
||||
|
||||
if (($x=$result->count()) == 1)
|
||||
return $result->first();
|
||||
|
||||
throw new ModelNotFoundException(sprintf('Query brings back %d record(s) called for singleOrFail()',$x));
|
||||
});
|
||||
|
||||
// When a query should return 1 object, or NULL if it doesnt
|
||||
Builder::macro('single',function () {
|
||||
$result = $this->get();
|
||||
|
||||
if ($result->count() == 1)
|
||||
return $result->first();
|
||||
|
||||
return NULL;
|
||||
});
|
||||
|
||||
// When a query should return 1 object, or NULL if it doesnt
|
||||
Builder::macro('singleOrNew',function ($args) {
|
||||
$result = $this->where($args)->get();
|
||||
|
||||
if ($result->count() == 1)
|
||||
return $result->first();
|
||||
|
||||
return $this->newModelInstance($args);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user