PHP code example of makidizajnerica / laravel-expanded
1. Go to this page and download the library: Download makidizajnerica/laravel-expanded 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/ */
makidizajnerica / laravel-expanded example snippets
namespace App\Models;
use App\Collections\UserCollection;
use Illuminate\Database\Eloquent\Model;
use MakiDizajnerica\Expanded\Concerns\Models\Collectionable;
class User extends Model
{
use Collectionable;
/**
* @var class-string
*/
protected $collection = UserCollection::class;
// ...
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use MakiDizajnerica\Expanded\Concerns\Models\Routable;
class User extends Model
{
use Routable;
/**
* @var string
*/
protected $routeKeyName = 'uuid';
protected $fillable = [
'uuid',
'username',
'email',
// ...
];
// ...
}
namespace App\Enums;
use MakiDizajnerica\Expanded\Concerns\EnumToArray;
enum UserType: int
{
use EnumToArray;
case user = 1;
case moderator = 2;
case admin = 3;
}
// Get the names of the cases:
var_dump(UserType::names());
// array(3) {
// [0]=> string(4) "user"
// [1]=> string(9) "moderator"
// [2]=> string(5) "admin"
// }
// Get the values of the cases:
var_dump(UserType::values());
// array(3) {
// [0]=> int(1)
// [1]=> int(2)
// [2]=> int(3)
// }
// Get array representation of the enum:
var_dump(UserType::toArray());
// array(3) {
// ["user"]=> int(1)
// ["moderator"]=> int(2)
// ["admin"]=> int(3)
// }
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
use MakiDizajnerica\Expanded\Mixins\ArrMixin;
class AppServiceProvider extends ServiceProvider
{
// ...
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Arr::mixin(new ArrMixin);
}
// ...
}
use Illuminate\Support\Str;
use Illuminate\Support\ServiceProvider;
use MakiDizajnerica\Expanded\Mixins\StrMixin;
class AppServiceProvider extends ServiceProvider
{
// ...
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Str::mixin(new StrMixin);
}
// ...
}
use Illuminate\Support\Str;
$username = Str::username('[email protected]');
var_dump($username);
// string(10) "randomuser123"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.