Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f801001571 | ||
|
45be8553a2 | ||
|
9798f6aa7d |
@@ -82,7 +82,7 @@
|
|||||||
<div class="col-md-4 col-sm-4">
|
<div class="col-md-4 col-sm-4">
|
||||||
<ul class="social-footer list-unstyled list-inline pull-right">
|
<ul class="social-footer list-unstyled list-inline pull-right">
|
||||||
@foreach ($so->social as $social)
|
@foreach ($so->social as $social)
|
||||||
<li><a href="{{ $social['url'] }}"><i class="fa fa-{{ $social['name'] }}"></i></a></li>
|
<li><a href="{{ $social['url'] }}"><i class="fab fa-{{ $social['name'] }}"></i></a></li>
|
||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -10,8 +10,8 @@ trait ScopeActive
|
|||||||
/**
|
/**
|
||||||
* Only query active records
|
* 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