This package is collect my methods and function use frequently in laravel be careful if you are using this package it can be breaking chage anytime. Please fork it to your own repository, And send some PR for cool feature if you need to contribute it.
1 - Install the package via Composer:
composer require anthoz69/anter
The package will automatically register its service provider.
Note: If you are using Laravel 5.5, the steps 2 and 3, for providers and aliases, are unnecessaries. Dod Package supports Laravel new Package Discovery.
2 - You need to update your application configuration in order to register the package so it can be loaded by Laravel, just update your config/app.php
file adding the following code at the end of your 'providers'
section:
config/app.php
'providers' => [
// other providers ommited
anthoz69\anter\Providers\AntherServiceProvider::class,
],
Save file from frontend upload in laravel and generate unique file name before store file.
AnterStore::store($path, $file)->save();
AnterStore::url($path);
AnterStore::delete($path);
Save file from frontend upload in laravel and resize image.
// Store image in /storage/app/public/user/cover
// save() method will return full path of image.
$image = AnterStore::make('user/cover', $request->file('image'));
$image->crop(300, 450)->save(); // Crop image from center size 300px x 450px.
$image->fit(300, 300, true)->save(); // Resize and crop image to 300px x 300px and prevent up size image if set true.
$image->resize(300, true)->save(); // Resize to width 300px and prevent up size image if set true.
$image->width(); // Get width of image.
$image->height(); // Get height of image.
2 => 2.00
4.75668 => 4.75
setCurrency($number, $percision = 2); // truncate and round
truncate($number, $percision = 2); // truncate and not round number
isRoutePrefix If your url start with /admin or something will place active class
to html attribute class it good for hierarchy menu.
isRouteMatch('/admin/*', $class = 'active');
e.g. your url /admin/user/create
.
<li class="{{ isRouteMatch('/admin/*', 'active-patent-menu') }}"></li>
// output if url start with /admin/user
<li class="active-patent-menu"></li>
isRoute When user access to url and laravel route name matched it will output class.
isRoute($routeName = '', $class = 'active');
isRoute('user.create', 'active-color-menu'); // result: active-color-menu
isRoute('user.create'); // result: active
get id from url support Youtube, Vimeo if wrong format will return null
.
getYoutubeId('https://www.youtube.com/watch?v=aAzUC8vNtgo'); // output: aAzUC8vNtgo
getVimeoId('https://vimeo.com/68529790'); // output: 68529790
getVideoProvider('https://www.youtube.com/watch?v=aAzUC8vNtgo'); // output: youtube
Send timestamp (created_at, updated_at in laravel) to function will return string time.
getTHMonth($index, $short = true);
getDateTH($strDate, $shortMonth = true, $time = false);
getTimeFromDate($strDate, $second = true);
e.g.
getTHMonth(1); // มกราคม
getTHMonth(1, true); // ม.ค.
getDateTH('2019-07-17 16:07:42'); // 17 ก.ค. 2562
getDateTH('2019-07-17 16:07:42', false); // 17 กรกฏาคม 2562
getDateTH('2019-07-17 16:07:42', true, true); // 17 ก.ค. 2562 16:07
getTimeFromDate('2019-07-17 16:07:42'); // 16:07
getTimeFromDate('2019-07-17 16:07:42', true); // 16:07:42
If you discover any security related issues, please open the issue or send me some cool PR.
Please see contributing.md for details and a todolist.
license is under MIT. Please see the license file for more information.