PHP code example of abdullah-mateen / laravel-helping-material
1. Go to this page and download the library: Download abdullah-mateen/laravel-helping-material 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/ */
abdullah-mateen / laravel-helping-material example snippets
// config/app.php
'providers' => [
AbdullahMateen\LaravelHelpingMaterial\LaravelHelpingMaterialServiceProvider::class,
],
return [
'api' => [
'response_keys' => [
'snake_case' => env('LHM_SNAKE_CASE', false),
],
],
'models' => [
'should_be_strict' => env('LHM_SHOULD_BE_STRICT', false),
'user' => App\Models\User::class,
],
'storage' => [
'folder' => env('STORAGE_FOLDER', 'storage'),
'shared' => [
'enabled' => env('SHARED_STORAGE', false),
'path' => env('SHARED_STORAGE_PATH', null),
],
],
'media_service' => [
'model' => AbdullahMateen\LaravelHelpingMaterial\Models\Media::class,
'media_disk_enum' => AbdullahMateen\LaravelHelpingMaterial\Enums\Media\MediaDiskEnum::class,
'extensions' => [
'image' => ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'svg', 'webp'],
'audio' => ['mp3', 'aac', 'ogg', 'flac', 'alac', 'wav', 'aiff', 'dsd', 'pcm'],
'video' => ['mp3', 'mp4', 'mov', 'webm'],
'document' => ['pdf', 'doc', 'docx', 'csv', 'xlx', 'txt', 'pptx', 'divx'],
'archive' => ['7z', 's7z', 'apk', 'jar', 'rar', 'tar.gz', 'tgz', 'tarZ', 'tar', 'zip', 'zipx'],
],
],
];
$user = auth_user();
$title = webpage_title('Dashboard');
$route = route_url_to_name('https://example.test/dashboard');
$formatted = display_number(12500.5);
use AbdullahMateen\LaravelHelpingMaterial\Enums\User\AccountStatusEnum;
use AbdullahMateen\LaravelHelpingMaterial\Enums\User\GenderEnum;
use AbdullahMateen\LaravelHelpingMaterial\Enums\User\RoleEnum;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
protected function casts(): array
{
return [
'role' => RoleEnum::class,
'gender' => GenderEnum::class,
'status' => AccountStatusEnum::class,
];
}
}
RoleEnum::Customer->value;
RoleEnum::toArray();
RoleEnum::toFullArray();
RoleEnum::fromName('Customer');
'media_service' => [
'model' => App\Models\Media::class,
],
use AbdullahMateen\LaravelHelpingMaterial\Enums\User\RoleEnum;
use Illuminate\Support\Facades\Route;
Route::get('/admin', AdminController::class)
->middleware('authorize:1001,3001');
Route::get('/staff', StaffController::class)
->middleware('authorize:' . RoleEnum::column('value', 'admins', true));
return response()->response(
response: 200,
message: 'Profile updated',
data: ['user' => $user],
);
return response()->everythingOK('Saved successfully');
return response()->invalid('Invalid data provided');
return response()->unauthenticated();
return response()->loginAttemptFailed();
return response()->authNotFound();
return response()->refreshToken(['token' => $token]);
return response()->loggedIn(['user' => $user]);
return response()->loggedOut();
use AbdullahMateen\LaravelHelpingMaterial\Services\Media\ImageService;
use Illuminate\Http\Request;
public function updateAvatar(Request $request): array
{
$request->validate([
'avatar' => [' disk: 'public',
);
}
use AbdullahMateen\LaravelHelpingMaterial\Services\Media\DocumentService;
$result = DocumentService::store(
file: $request->file('document'),
path: 'uploads/documents',
disk: 'public',
);
$result = DocumentService::persist(
file: $request->file('document'),
model: null,
path: 'unattached/documents',
disk: 'public',
);
use AbdullahMateen\LaravelHelpingMaterial\Services\Media\MediaService;
$media = app(MediaService::class)
->filesStore($request->file('attachments'), 'tickets/'.$ticket->id, null, 'public')
->save($ticket);
$data = $media->getData()->values()->all();
$ids = $media->getIds(false);
$media = ImageService::service($request->file('avatar'))
->thumbnail(fn ($image) => $image->scale(width: 320))
->store('users/'.$user->id.'/profile', 'avatar', 'public')
->save($user);
$temp = DocumentService::persist(
file: $request->file('document'),
model: null,
path: 'temporary/documents',
disk: 'public',
);
$media = app(MediaService::class)
->model($user)
->move(
values: $temp['ids'],
fromDisk: 'public',
fromPath: 'temporary/documents',
toDisk: 'public',
toPath: 'users/'.$user->id.'/documents',
column: 'id',
);
$media = app(MediaService::class)
->model($user)
->move(
values: [1, 2, 3],
fromDisk: 'public',
fromPath: 'users/'.$user->id.'/documents',
toDisk: 's3',
toPath: 'users/'.$user->id.'/documents',
column: 'id',
);
$media = DocumentService::service($request->file('document'))
->store('replacement/documents', null, 'public')
->update($mediaId, 'public', 'id');
// Delete database rows and physical files.
app(MediaService::class)->destroy([1, 2, 3], 'id', true);
// Delete database rows only.
app(MediaService::class)->destroy([1, 2, 3], 'id', false);
// Delete a physical file only.
app(MediaService::class)->remove('report.pdf', 'uploads/documents', 'public');
ImageService::store($file, 'images', null, 'public');
AudioService::store($file, 'audio', null, 'public');
VideoService::store($file, 'videos', null, 'public');
DocumentService::store($file, 'documents', null, 'public');
ArchiveService::store($file, 'archives', null, 'public');
use AbdullahMateen\LaravelHelpingMaterial\Interfaces\ColorsInterface;
class Badge implements ColorsInterface
{
public function className(): string
{
return 'bg-'.self::SUCCESS_CLASS;
}
public function colorCode(): string
{
return self::SUCCESS;
}
}
use AbdullahMateen\LaravelHelpingMaterial\Rules\Throttle;
$request->validate([
'email' => ['sh
php artisan storage:link
sh
php artisan vendor:publish --tag=laravel-helping-material-config
sh
php artisan vendor:publish --tag=laravel-helping-material-config
sh
php artisan vendor:publish --tag=laravel-helping-material-migrations
sh
php artisan lhm:publish
sh
php artisan lhm:publish
sh
php artisan make:lhm-model Product
php artisan make:lhm-model Product -mfs
json
{
"autoload": {
"files": [
"app/Helpers/custom.php"
]
}
}
sh
composer dump-autoload
sh
php artisan lhm:publish
# choose Models
sh
php artisan lhm:publish
# choose Resources