Testing needs to have the database seeded
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Passport\Passport;
|
||||
|
||||
use App\Traits\SingleOrFail;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
use SingleOrFail;
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
@@ -25,38 +28,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// 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 \Exception(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) {
|
||||
//dd(['func'=>func_get_args(),'args'=>$args,'this'=>$this]);
|
||||
$result = $this->where($args)->get();
|
||||
|
||||
if ($result->count() == 1) {
|
||||
return $result->first();
|
||||
}
|
||||
|
||||
return $this->newModelInstance($args);
|
||||
});
|
||||
static::bootSingleOrFail();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user