PHP code example of laracraft-tech / laravel-useful-traits
1. Go to this page and download the library: Download laracraft-tech/laravel-useful-traits library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
laracraft-tech / laravel-useful-traits example snippets
use LaracraftTech\LaravelUsefulAdditions\Traits\UsefulEnums;
enum PaymentType: int
{
use UsefulEnums;
case Pending = 1;
case Failed = 2;
case Success = 3;
}
PaymentType::names(); // return ['Pending', 'Failed', 'Success']
PaymentType::values(); // return [1, 2, 3]
PaymentType::array(); // return ['Pending' => 1, 'Failed' => 2, 'Success' => 3]
use LaracraftTech\LaravelUsefulAdditions\Traits\UsefulScopes;
$class = new class extends Model
{
use UsefulScopes;
protected $timestamps = false;
protected $table = 'scope_tests';
};
$class->create([
'foo' => 'foo',
'bar' => 'bar',
'quz' => 'quz',
]);
$class::query()->selectAllBut(['foo'])->first()->toArray();
// return ['bar' => 'bar', 'quz' => 'quz']
use LaracraftTech\LaravelUsefulAdditions\Traits\RefreshDatabaseFast;
uses(RefreshDatabaseFast::class);
it('does_something', function() {
// ...
});
use LaracraftTech\LaravelUsefulAdditions\Traits\RefreshDatabaseFast;
use Tests\TestCase;
class MyTest extends TestCase
{
use RefreshDatabaseFast;
/** @test **/
public function it_does_something()
{
// ...
}
}