<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
abdullah-mateen / laravel-helping-metarial example snippets
use \AbdullahMateen\LaravelHelpingMaterial\Enums\User\AccountStatusEnum;
use \AbdullahMateen\LaravelHelpingMaterial\Enums\User\GenderEnum;
use \AbdullahMateen\LaravelHelpingMaterial\Enums\User\RoleEnum;
class User extends Authenticatable {
protected $casts = [
'role' => RoleEnum::class,
'gender' => GenderEnum::class,
'status' => AccountStatusEnum::class,
];
// ...
}
User::create([
'name' => 'John Doe',
'email' => '[email protected]',
'password' => Hash::male('password'),
'role' => RoleEnum::Customer, // or you can use its value RoleEnum::Customer->value
'gender' => GenderEnum::Male, // or you can use its value GenderEnum::Male->value
'status' => AccountStatusEnum::Unverified, // or you can use its value AccountStatusEnum::Unverified->value
]);
$user = auth_user();
$routeName = route_url_to_name('https://example.com') // will return 'index'
if (is_current_route('dashboard')) {
// do something
}
// and much more ...
use \AbdullahMateen\LaravelHelpingMaterial\Interfaces\ColorsInterface;
use \AbdullahMateen\LaravelHelpingMaterial\Enums\User\AccountStatusEnum;
class Example implements ColorsInterface {
protected $casts = [
'status' => AccountStatusEnum::class,
];
public function getColorClass() {
return 'bg-' . self::SUCCESS_CLASS // bg-success: for background colors
// return self::SUCCESS_CLASS // success: for text colors
}
public function getColorCode() {
return self::SUCCESS // #28a745
}
public function getStatusColor() {
return $this->status->color(); // Using Enum 'color' function
}
}
// web.php File
use \AbdullahMateen\LaravelHelpingMaterial\Enums\User\RoleEnum;
Route::get('/dashboard', [DashboardController::class, 'index'])->middleware('authorize:1001,3001')
Route::get('/dashboard', [DashboardController::class, 'index'])->middleware('authorize:' . RoleEnum::column('value', 'admins', true))
// if you have published it
Route::get('/dashboard', [DashboardController::class, 'index'])->middleware('custom-authorize:1001,3001')