久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 Laravel 5 中創(chuàng)建全局輔助函數(shù)?

How do I make global helper functions in laravel 5?(如何在 Laravel 5 中創(chuàng)建全局輔助函數(shù)?)
本文介紹了如何在 Laravel 5 中創(chuàng)建全局輔助函數(shù)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如果我想為一些 oauth 的東西制作一個 currentUser() 函數(shù),我正在做的地方我可以在視圖或控制器中使用它(想想 rails,你在哪里做 helper_method: current_user 在應(yīng)用程序控制器中).

If I wanted to make a currentUser() function for some oauth stuff I am doing where I can use it in a view or in a controller (think rails, where you do helper_method: current_user in the application controller).

我讀到的所有內(nèi)容都說明創(chuàng)建一個 helpers 文件夾并在那里添加函數(shù),然后你就可以這樣做 Helpers::functionName 這是正確的方法嗎?

Everything I read states to create a helpers folder and add the function there and then that way you can do Helpers::functionName Is this the right way to do this?

創(chuàng)建可在刀片模板和控制器中使用的輔助函數(shù)的laravel 方式"是什么?

Whats the "laravel way" of creating helper functions that can be used in blade templates and controllers?

推薦答案

在您的 app/Helpers 目錄中創(chuàng)建一個新文件,將其命名為 AnythingHelper.php我的助手的一個例子是:

Create a new file in your app/Helpers directory name it AnythingHelper.php An example of my helper is :

<?php
function getDomesticCities()
{
$result = AppPackage::where('type', '=', 'domestic')
    ->groupBy('from_city')
    ->get(['from_city']);

return $result;
}

通過以下命令為你的助手生成一個服務(wù)提供者

generate a service provider for your helper by following command

php artisan make:provider HelperServiceProvider

在你新生成的HelperServiceProvider.php的注冊函數(shù)中添加如下代碼

in the register function of your newly generated HelperServiceProvider.php add following code

require_once app_path('Helpers/AnythingHelper.php');

現(xiàn)在在你的 config/app.php 中加載這個服務(wù)提供者,你就完成了

now in your config/app.php load this service provider and you are done

'AppProvidersHelperServiceProvider',

這篇關(guān)于如何在 Laravel 5 中創(chuàng)建全局輔助函數(shù)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數(shù))
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數(shù)中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應(yīng)內(nèi)容必須是實現(xiàn) __toString()、“boolean和“boolean的字符串或?qū)ο?移動到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 国产精品一区2区 | 免费同性女女aaa免费网站 | 春色av| 天堂色综合 | jizz视频| 欧美精品一区在线 | 欧美成人在线网站 | 91久久精品视频 | 国产午夜三级一区二区三 | 七七婷婷婷婷精品国产 | 国产精品久久久久久久久久免费看 | 欧美一区二区久久 | 国产免费看| 精品国产综合 | 日韩在线一区视频 | 91麻豆精品国产91久久久更新资源速度超快 | 日韩一区二区三区视频在线观看 | 在线视频亚洲 | 黄网站在线播放 | 日韩精品一区在线观看 | 欧美一级做a爰片免费视频 国产美女特级嫩嫩嫩bbb片 | 久久午夜剧场 | 黄色一级免费 | 国产成人免费视频网站高清观看视频 | 一区二区在线不卡 | 欧美xxxx在线 | 久久久久久久久久久蜜桃 | 在线观看免费观看在线91 | 亚洲国产欧美91 | 色资源在线 | 欧美1区2区 | 免费视频一区 | 欧美日韩视频一区二区 | 国产美女久久久 | 九九热在线免费视频 | 欧美视频网 | 日本大片在线播放 | 美女一区 | 日韩在线视频播放 | 精品久久久久久国产 | av在线免费观看网站 |