Laravel 6 Create Custom Helper Function, composer dump-autoload (ok)
https://www.itsolutionstuff.com/post/laravel-6-create-custom-helper-functionexample.html
"autoload": {
"files": [
"app/helpers.php"
]
},<?php
function productImagePath($image_name) {
return public_path('images/products/' . $image_name);
}
function changeDateFormate($date, $date_format) {
return \Carbon\Carbon::createFromFormat('Y-m-d', $date)->format($date_format);
}
?><?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
use App\Http\Controllers\HomeController;
Route::get('/', function () {
dd('Welcome to simple user route file.');
});
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('helper', function () {
$imageName = 'example.png';
$fullpath = productImagePath($imageName);
dd($fullpath);
});
Route::get('helper2', function () {
$newDateFormat = changeDateFormate(date('Y-m-d'), 'm/d/Y');
dd($newDateFormat);
});Laravel 6 Create Custom Helper Function
PreviousTự tạo helper function cho riêng mình trong project LaravelNextLaravel - Custom Helper Facade Class Example from scratch (ok)
Last updated
