亚洲成A人片在线观看网站_成年网站免费视频A在线双飞_日日日日做夜夜夜夜无码_久久夜色撩人精品国产小说

Laravel 8 備忘清單

Laravel 8 備忘清單是最好的 Laravel 代碼段和備忘清單參考

入門

Artisan

# 5.1.11 新增://laravel.com/docs/authorization#creating-policies
$ php artisan make:policy PostPolicy
# 顯示給定命令的幫助
$ php artisan --help-h
# 不輸出任何信息
$ php artisan --quiet-q
# 顯示此應用程序版本
$ php artisan --version-V
# 不要問任何互動問題
$ php artisan --no-interaction OR -n
# 強制 ANSI 輸出
$ php artisan --ansi
# 禁用 ANSI 輸出
$ php artisan --no-ansi
# 命令應運行的環境
$ php artisan --env
# -v|vv|vvv 增加消息的詳細程度:1 表示正常輸出,2 表示更詳細的輸出,3 表示調試
$ php artisan --verbose
# 刪除編譯的類文件
$ php artisan clear-compiled
# 顯示當前框架環境
$ php artisan env
# 顯示命令的幫助
$ php artisan help
# 列出命令
$ php artisan list
# 與您的應用程序交互
$ php artisan tinker
# 將應用程序置于維護模式
$ php artisan down
# 使應用程序退出維護模式
$ php artisan up
# 優化框架以獲得更好的性能
# --force 強制寫入已編譯的類文件
# --psr 不要優化 Composer dump-autoload
$ php artisan optimize [--force] [--psr]
# 在 PHP 開發服務器上提供應用程序
$ php artisan serve
# 更改默認端口
$ php artisan serve --port 8080
# 讓它在本地主機之外工作
$ php artisan serve --host 0.0.0.0
# 設置應用命名空間
$ php artisan app:name namespace
# 刷新過期的密碼重置令牌
$ php artisan auth:clear-resets
# 刷新應用程序緩存
$ php artisan cache:clear
# 為緩存數據庫表創建遷移
$ php artisan cache:table
# 創建緩存文件以加快配置加載
$ php artisan config:cache
# 刪除配置緩存文件
$ php artisan config:clear
# 在節目中
$exitCode = Artisan::call('config:cache');
# 用記錄播種數據庫
# --class 根播種器的類名(默認值:"DatabaseSeeder")
# --database 種子的數據庫連接
# --force 強制操作在生產中運行
$ php artisan db:seed [--class[="..."]] [--database[="..."]] [--force]

# 根據注冊生成缺失的事件和處理程序
$ php artisan event:generate

# 創建一個新的命令處理程序類
# --command 處理程序處理的命令類
$ php artisan handler:command [--command="..."] name
# 創建一個新的事件處理程序類
# --event 處理程序處理的事件類
# --queued 表示事件處理程序應該排隊
$ php artisan handler:event [--event="..."] [--queued] name

# 設置應用程序密鑰
$ php artisan key:generate

# 默認情況下,這會創建一個不會推送到隊列的自我處理命令
# 傳遞 --handler 標志以生成處理程序,傳遞 --queued 標志以使其排隊
$ php artisan make:command [--handler] [--queued] name
# 創建一個新的 Artisan 命令
#   --command 應分配的終端命令。 (默認值:“命令:名稱”)
make:console [--command[="..."]] name
# 創建一個新的足智多謀的控制器
# --plain 生成一個空的控制器類
$ php artisan make:controller [--plain] name
$ php artisan make:controller App\\Admin\\Http\\Controllers\\DashboardController
# 創建一個新的事件類
$ php artisan make:event name
# 新建一個中間件類
$ php artisan make:middleware name
# 創建一個新的遷移文件
# --create 要創建的表
# --table 要遷移的表
$ php artisan make:migration [--create[="..."]] [--table[="..."]] name
# 創建一個新的 Eloquent 模型類
$ php artisan make:model name
# 創建一個新的服務提供者類
$ php artisan make:provider name
# 新建一個表單請求類
$ php artisan make:request name
# 數據庫遷移
# --database 要使用的數據庫連接
# --force 強制操作在生產中運行
# --path 要執行的遷移文件的路徑
# --pretend 轉儲將要運行的 SQL 查詢
# --seed 指示是否應重新運行種子任務
$ php artisan migrate [--database[="..."]] [--force] [--path[="..."]] [--pretend] [--seed]
# 創建遷移存儲庫
$ php artisan migrate:install [--database[="..."]]
# 創建一個新的遷移文件
# --seeder 根播種機的類名。
$ php artisan migrate:refresh [--database[="..."]] [--force] [--seed] [--seeder[="..."]]
# 回滾所有數據庫遷移
# --pretend 轉儲將要運行的 SQL 查詢。
$ php artisan migrate:reset [--database[="..."]] [--force] [--pretend]
# 回滾上次數據庫遷移
$ php artisan migrate:rollback [--database[="..."]] [--force] [--pretend]
# 顯示上/下遷移列表
$ php artisan migrate:status
# 為隊列作業數據庫表創建遷移
$ php artisan queue:table
# 收聽給定的隊列
# --queue 要監聽的隊列
# --delay 延遲失敗作業的時間量(默認值:0)
# --memory 以兆字節為單位的內存限制(默認值:128)
# --timeout 超時前作業可能運行的秒數(默認值:60)
# --sleep 在檢查作業隊列之前等待的秒數(默認值:3)
# --tries 在記錄失敗之前嘗試作業的次數(默認值:0)
$ php artisan queue:listen [--queue[="..."]] [--delay[="..."]] [--memory[="..."]] [--timeout[="..."]] [--sleep[="..."]] [--tries[="..."]] [connection]
# 列出所有失敗的隊列作業
$ php artisan queue:failed
# 為失敗隊列作業數據庫表創建遷移
$ php artisan queue:failed-table
# 刷新所有失敗的隊列作業
$ php artisan queue:flush
# 刪除失敗的隊列作業
$ php artisan queue:forget
# 在完成當前作業后重新啟動隊列工作守護進程
$ php artisan queue:restart
# 重試一個失敗的隊列作業(id:失敗作業的ID)
$ php artisan queue:retry id
# 訂閱 Iron.io 推送隊列的 URL
# 隊列:Iron.io 隊列的名稱
# url:要訂閱的URL
# --type 隊列的推送類型
$ php artisan queue:subscribe [--type[="..."]] queue url
# 處理隊列中的下一個作業
# --queue 要監聽的隊列
# --daemon 以守護進程模式運行worker
# --delay 延遲失敗作業的時間量(默認值:0)
# --force 即使在維護模式下也強制 worker 運行
# --memory 以兆字節為單位的內存限制(默認值:128)
# --sleep 沒有工作時休眠的秒數(默認值:3)
# --tries 在記錄失敗之前嘗試作業的次數(默認值:0)
$ php artisan queue:work [--queue[="..."]] [--daemon] [--delay[="..."]] [--force] [--memory[="..."]] [--sleep[="..."]] [--tries[="..."]] [connection]

# 創建路由緩存文件以加快路由注冊
$ php artisan route:cache
# 移除路由緩存文件
$ php artisan route:clear
# 列出所有注冊的路由
$ php artisan route:list

# 運行預定的命令
$ php artisan schedule:run

# 為會話數據庫表創建遷移
$ php artisan session:table

# 從供應商包中發布任何可發布的資產
# --force 覆蓋任何現有文件
# --provider 具有您要發布的資產的服務提供商
# --tag 包含您要發布的資產的標簽
$ php artisan vendor:publish [--force] [--provider[="..."]] [--tag[="..."]]
$ php artisan tail [--path[="..."]] [--lines[="..."]] [connection]

Composer

$ composer create-project laravel/laravel folder_name
$ composer install
$ composer update
$ composer dump-autoload [--optimize]
$ composer self-update
$ composer require [options] [--] [vender/packages]...

Config

Config::get('app.timezone');
// 使用默認值獲取
Config::get('app.timezone', 'UTC');
// 設置配置
Config::set('database.default', 'sqlite');

Environment

$environment = app()->environment();
$environment = App::environment();
$environment = $app->environment();
// 環境是當地的
if ($app->environment('local')){}
// 環境要么是本地的,要么是暫存的……
if ($app->environment('local', 'staging')){}

Log 日志

// 記錄器提供 RFC 5424 中定義的七個日志記錄級別:
// 調試、信息、通知、警告、錯誤、嚴重和警報
// debug, info, notice, warning, error, critical, 和 alert
Log::info('info');
Log::info('info',array('context'=>'additional info'));
Log::error('error');
Log::warning('warning');
// 獲取獨白實例
Log::getMonolog();
// 添加監聽器
Log::listen(function($level, $message, $context) {});

查詢記錄

// 啟用日志
DB::connection()->enableQueryLog();
// 獲取已執行查詢的數組
DB::getQueryLog();

URL

URL::full();
URL::current();
URL::previous();
URL::to('foo/bar', $parameters, $secure);
URL::action('NewsController@item', ['id'=>123]);
// 需要在適當的命名空間中
URL::action('Auth\AuthController@logout');
URL::action('FooController@method', $parameters, $absolute);
URL::route('foo', $parameters, $absolute);
URL::secure('foo/bar', $parameters);
URL::asset('css/foo.css', $secure);
URL::secureAsset('css/foo.css');
URL::isValidUrl('//example.com');
URL::getRequest();
URL::setRequest($request);

Event

Event::fire('foo.bar', array($bar));
// 向調度程序注冊一個事件偵聽器
// void listen(string|array $events, mixed $listener, int $priority)
Event::listen('App\Events\UserSignup', function($bar){});
Event::listen('foo.*', function($bar){});
Event::listen('foo.bar', 'FooHandler', 10);
Event::listen('foo.bar', 'BarHandler', 5);
// 停止傳播事件
// 您可以通過從處理程序返回 false 來執行此操作
Event::listen('foor.bar', function($event){ return false; });
Event::subscribe('UserEventHandler');

Pagination

// 自動魔術分頁
Model::paginate(15);
Model::where('cars', 2)->paginate(15);
// 僅“下一個”和“上一個”
Model::where('cars', 2)->simplePaginate(15);
// 手動分頁器
Paginator::make($items, $totalItems, $perPage);
// 在視圖中打印頁面導航器
$variable->links();

Lang

App::setLocale('en');
Lang::get('messages.welcome');
Lang::get('messages.welcome', array('foo' => 'Bar'));
Lang::has('messages.welcome');
Lang::choice('messages.apples', 10);
// Lang::get alias
trans('messages.welcome');

File

File::exists('path');
File::get('path');
File::getRemote('path');
// 通過請求獲取文件的內容
File::getRequire('path');
// 需要一次給定的文件
File::requireOnce('path');
// 寫一個文件的內容
File::put('path', 'contents');
// 附加到文件
File::append('path', 'data');
// 刪除給定路徑的文件
File::delete('path');
// 將文件移動到新位置
File::move('path', 'target');
// 將文件復制到新位置
File::copy('path', 'target');
// 從文件路徑中提取文件擴展名
File::extension('path');
// 獲取給定文件的文件類型
File::type('path');
// 獲取給定文件的文件大小
File::size('path');
// 獲取文件的最后修改時間
File::lastModified('path');
// 確定給定路徑是否為目錄
File::isDirectory('directory');
// 確定給定路徑是否可寫
File::isWritable('path');
// 確定給定路徑是否為文件
File::isFile('file');
// 查找與給定模式匹配的路徑名
File::glob($patterns, $flag);
// 獲取目錄中所有文件的數組
File::files('directory');
// 從給定目錄中獲取所有文件(遞歸)
File::allFiles('directory');
// 獲取給定目錄中的所有目錄
File::directories('directory');
// 創建目錄
File::makeDirectory('path',  $mode = 0777, $recursive = false);
// 將目錄從一個位置復制到另一個位置
File::copyDirectory('directory', 'destination', $options = null);
// 遞歸刪除目錄
File::deleteDirectory('directory', $preserve = false);
// 清空指定目錄下的所有文件和文件夾
File::cleanDirectory('directory');

SSH

執行命令

SSH::run(array $commands);
SSH::into($remote)->run(array $commands); 
// 指定遠程,否則假定默認
SSH::run(array $commands, function($line)
{
  echo $line.PHP_EOL;
});

任務

// 定義
SSH::define($taskName, array $commands);
// 執行
SSH::task($taskName, function($line)
{
  echo $line.PHP_EOL;
});

SFTP 上傳

SSH::put($localFile, $remotePath);
SSH::putString($string, $remotePath);
Cookie::get('key');
Cookie::get('key', 'default');
// 創建一個永遠持續的 cookie
Cookie::forever('key', 'value');
// 創建一個持續 N 分鐘的 cookie
Cookie::make('key', 'value', 'minutes');
// 在創建響應之前設置 cookie
Cookie::queue('key', 'value', 'minutes');
// 忘記cookie
Cookie::forget('key');
// 發送帶有響應的 cookie
$response = Response::make('Hello World');
// 將 cookie 添加到響應中
$response->withCookie(Cookie::make('name', 'value', $minutes));

UnitTest

安裝并運行

// 添加到作曲家并更新:
"phpunit/phpunit": "4.0.*"
// 運行測試(從項目根目錄)
./vendor/bin/phpunit

斷言

$this->assertTrue(true);
$this->assertEquals('foo', $bar);
$this->assertCount(1,$times);
$this->assertResponseOk();
$this->assertResponseStatus(403);
$this->assertRedirectedTo('foo');
$this->assertRedirectedToRoute('route.name');
$this->assertRedirectedToAction('Controller@method');
$this->assertViewHas('name');
$this->assertViewHas('age', $value);
$this->assertSessionHasErrors();
// 斷言會話有給定鍵的錯誤...
$this->assertSessionHasErrors('name');
// 斷言會話有幾個鍵的錯誤...
$this->assertSessionHasErrors(array('name', 'age'));
$this->assertHasOldInput();

調用路由

$response = $this->call($method, $uri, $parameters, $files, $server, $content);
$response = $this->callSecure('GET', 'foo/bar');
$this->session(['foo' => 'bar']);
$this->flushSession();
$this->seed();
$this->seed($connection);

Cache

Cache::put('key', 'value', $minutes);
Cache::add('key', 'value', $minutes);
Cache::forever('key', 'value');
Cache::remember('key', $minutes, function(){ return 'value' });
Cache::rememberForever('key', function(){ return 'value' });
Cache::forget('key');
Cache::has('key');
Cache::get('key');
Cache::get('key', 'default');
Cache::get('key', function(){ return 'default'; });
Cache::tags('my-tag')->put('key','value', $minutes);
Cache::tags('my-tag')->has('key');
Cache::tags('my-tag')->get('key');
Cache::tags('my-tag')->forget('key');
Cache::tags('my-tag')->flush();
Cache::increment('key');
Cache::increment('key', $amount);
Cache::decrement('key');
Cache::decrement('key', $amount);
Cache::section('group')->put('key', $value);
Cache::section('group')->get('key');
Cache::section('group')->flush();

Session

Session::get('key');
// 從會話中返回一個項目
Session::get('key', 'default');
Session::get('key', function(){ return 'default'; });
// 獲取會話 ID
Session::getId();
// 在會話中放置一個鍵/值對
Session::put('key', 'value');
// 將值推送到會話中的數組中
Session::push('foo.bar','value');
// 返回會話中的所有項目
Session::all();
// 檢查一個項目是否被定義
Session::has('key');
// 從會話中刪除項目
Session::forget('key');
// 從會話中刪除所有項目
Session::flush();
// 生成新的會話標識符
Session::regenerate();
// 將鍵/值對閃存到會話
Session::flash('key', 'value');
// 刷新所有會話閃存數據
Session::reflash();
// 刷新當前閃存數據的一個子集
Session::keep(array('key1', 'key2'));

Response

return Response::make($contents);
return Response::make($contents, 200);
return Response::json(array('key' => 'value'));
return Response::json(array('key' => 'value'))
->setCallback(Input::get('callback'));
return Response::download($filepath);
return Response::download($filepath, $filename, $headers);
// 創建響應并修改標頭值
$response = Response::make($contents, 200);
$response->header('Content-Type', 'application/json');
return $response;
// 將 cookie 附加到響應
return Response::make($content)
->withCookie(Cookie::make('key', 'value'));

Request

// url: //xx.com/aa/bb
Request::url();
// 路徑:/aa/bb
Request::path();
// getRequestUri: /aa/bb/?c=d
Request::getRequestUri();
// 返回用戶的IP
Request::getClientIp();
// getUri: //xx.com/aa/bb/?c=d
Request::getUri();
// 獲取查詢字符串:c=d
Request::getQueryString();
// 獲取請求的端口方案(例如 80、443 等)
Request::getPort();
// 確定當前請求 URI 是否與模式匹配
Request::is('foo/*');
// 從 URI 中獲取一個段(基于 1 的索引)
Request::segment(1);
// 從請求中檢索標頭
Request::header('Content-Type');
// 從請求中檢索服務器變量
Request::server('PATH_INFO');
// 確定請求是否是 AJAX 調用的結果
Request::ajax();
// 確定請求是否通過 HTTPS
Request::secure();
// 獲取請求方法
Request::method();
// 檢查請求方法是否為指定類型
Request::isMethod('post');
// 獲取原始 POST 數據
Request::instance()->getContent();
// 獲取請求的響應格式
Request::format();
// 如果 HTTP Content-Type 標頭包含 */json,則為真
Request::isJson();
// 如果 HTTP Accept 標頭是 application/json,則為真
Request::wantsJson();

Container

App::bind('foo', function($app){ return new Foo; });
App::make('foo');
// 如果這個類存在,則返回
App::make('FooBar');
// 在容器中注冊共享綁定
App::singleton('foo', function(){ return new Foo; });
// 將現有實例注冊為在容器中共享
App::instance('foo', new Foo);
// 注冊與容器的綁定
App::bind('FooRepositoryInterface', 'BarRepository');
// 使用應用程序注冊服務提供商
App::register('FooServiceProvider');
// 監聽對象分辨率
App::resolving(function($object){});

Redirect

return Redirect::to('foo/bar');
return Redirect::to('foo/bar')->with('key', 'value');
return Redirect::to('foo/bar')->withInput(Input::get());
return Redirect::to('foo/bar')->withInput(Input::except('password'));
return Redirect::to('foo/bar')->withErrors($validator);
// 創建對先前位置的新重定向響應
return Redirect::back();
// 創建對命名路由的新重定向響應
return Redirect::route('foobar');
return Redirect::route('foobar', array('value'));
return Redirect::route('foobar', array('key' => 'value'));
// 創建對控制器操作的新重定向響應
return Redirect::action('FooController@index');
return Redirect::action('FooController@baz', array('value'));
return Redirect::action('FooController@baz', array('key' => 'value'));
// 如果未定義預期的重定向,則默認為 foo/bar。
return Redirect::intended('foo/bar');

Security

Hashing

Hash::make('secretpassword');
Hash::check('secretpassword', $hashedPassword);
Hash::needsRehash($hashedPassword);

Encryption

Crypt::encrypt('secretstring');
Crypt::decrypt($encryptedString);
Crypt::setMode('ctr');
Crypt::setCipher($cipher);

Queue

Queue::push('SendMail', array('message' => $message));
Queue::push('SendEmail@send', array('message' => $message));
Queue::push(function($job) use $id {});
// 多個工人的相同有效載荷
Queue::bulk(array('SendEmail', 'NotifyUser'), $payload);

Starting the queue listener

php artisan queue:listen
php artisan queue:listen connection
php artisan queue:listen --timeout=60
# 只處理隊列中的第一個作業
php artisan queue:work
# 以守護進程模式啟動一個隊列工作者
php artisan queue:work --daemon
# 為失敗的作業創建遷移文件
php artisan queue:failed-table
# 列出失敗的工作
php artisan queue:failed
# 通過 id 刪除失敗的作業
php artisan queue:forget 5
# 刪除所有失敗的作業
php artisan queue:flush

View

View::make('path/to/view');
View::make('foo/bar')->with('key', 'value');
View::make('foo/bar')->withKey('value');
View::make('foo/bar', array('key' => 'value'));
View::exists('foo/bar');
// 在所有視圖中共享一個值
View::share('key', 'value');
// 嵌套視圖
View::make('foo/bar')->nest('name', 'foo/baz', $data);
// 注冊視圖編輯器
View::composer('viewname', function($view){});
// 向作曲家注冊多個視圖
View::composer(array('view1', 'view2'), function($view){});
// 注冊作曲家類
View::composer('viewname', 'FooComposer');
View::creator('viewname', function($view){});

Validation

Validator::make(
array('key' => 'Foo'),
array('key' => 'required|in:Foo')
);
Validator::extend('foo', function($attribute, $value, $params){});
Validator::extend('foo', 'FooValidator@validate');
Validator::resolver(function($translator, $data, $rules, $msgs)
{
return new FooValidator($translator, $data, $rules, $msgs);
});

Rules

  • accepted
  • active_url
  • after:YYYY-MM-DD
  • before:YYYY-MM-DD
  • alpha
  • alpha_dash
  • alpha_num
  • array
  • between:1,10
  • confirmed
  • date
  • date_format:YYYY-MM-DD
  • different:fieldname
  • digits:value
  • digits_between:min,max
  • boolean
  • email
  • exists:table,column
  • image
  • in:foo,bar,...
  • not_in:foo,bar,...
  • integer
  • numeric
  • ip
  • max:value
  • min:value
  • mimes:jpeg,png
  • regex:[0-9]
  • required
  • required_if:field,value
  • required_with:foo,bar,...
  • required_with_all:foo,bar,...
  • required_without:foo,bar,...
  • required_without_all:foo,bar,...
  • same:field
  • size:value
  • timezone
  • unique:table,column,except,idColumn
  • url

Form

Form::open(array('url' => 'foo/bar', 'method' => 'PUT'));
Form::open(array('route' => 'foo.bar'));
Form::open(array('route' => array('foo.bar', $parameter)));
Form::open(array('action' => 'FooController@method'));
Form::open(array('action' => array('FooController@method', $parameter)));
Form::open(array('url' => 'foo/bar', 'files' => true));
Form::close();
Form::token();
Form::model($foo, array('route' => array('foo.bar', $foo->bar)));

Form Elements

Form::label('id', 'Description');
Form::label('id', 'Description', array('class' => 'foo'));
Form::text('name');
Form::text('name', $value);
Form::text('name', $value, array('class' => 'name'));
Form::textarea('name');
Form::textarea('name', $value);
Form::textarea('name', $value, array('class' => 'name'));
Form::hidden('foo', $value);
Form::password('password');
Form::password('password', array('placeholder' => 'Password'));
Form::email('name', $value, array());
Form::file('name', array('class' => 'name'));
Form::checkbox('name', 'value');
// 生成一個被選中的復選框
Form::checkbox('name', 'value', true, array('class' => 'name'));
Form::radio('name', 'value');
// 生成選定的無線電輸入
Form::radio('name', 'value', true, array('class' => 'name'));
Form::select('name', array('key' => 'value'));
Form::select('name', array('key' => 'value'), 'key', array('class' => 'name'));
Form::selectRange('range', 1, 10);
Form::selectYear('year', 2011, 2015);
Form::selectMonth('month');
Form::submit('Submit!', array('class' => 'name'));
Form::button('name', array('class' => 'name'));
Form::macro('fooField', function()
{
return '<input type="custom"/>';
});
Form::fooField();

String

// 將 UTF-8 值音譯為 ASCII
Str::ascii($value)
Str::camel($value)
Str::contains($haystack, $needle)
Str::endsWith($haystack, $needles)
// 用給定值的單個實例來限制字符串。
Str::finish($value, $cap)
Str::is($pattern, $value)
Str::length($value)
Str::limit($value, $limit = 100, $end = '...')
Str::lower($value)
Str::words($value, $words = 100, $end = '...')
Str::plural($value, $count = 2)
// 生成更真實的“隨機”字母數字字符串。
Str::random($length = 16)
// 生成“隨機”字母數字字符串。
Str::quickRandom($length = 16)
Str::upper($value)
Str::title($value)
Str::singular($value)
Str::slug($title, $separator = '-')
Str::snake($value, $delimiter = '_')
Str::startsWith($haystack, $needles)
// 將值轉換為大寫大小寫。
Str::studly($value)
Str::macro($name, $macro)

Blade

// 在模板中顯示一個部分
@yield('name')
@extends('layout.name')
// 開始一個部分
@section('name')
// 結束一段
@stop
// 結束一個部分并屈服
@section('sidebar')
@show
@parent

@include('view.name')
@include('view.name', array('key' => 'value'));
@lang('messages.name')
@choice('messages.name', 1);

@if
@else
@elseif
@endif

@unless
@endunless

@for
@endfor

@foreach
@endforeach

@while
@endwhile

// 預測 4.2 功能
@forelse($users as $user)
@empty
@endforelse

// Echo 內容
{{ $var }}
// Echo 轉義內容
{{{ $var }}}
// Echo 未轉義的內容; 5.0 功能
{!! $var !!}
{{-- Blade Comment --}}
// 檢查存在后 Echo 數據
{{{ $name or 'Default' }}}
// 顯示帶有花括號的原始文本
@{{ This will not be processed by Blade }}

HTML

HTML::macro('name', function(){});
// 將 HTML 字符串轉換為實體
HTML::entities($value);
// 將實體轉換為 HTML 字符
HTML::decode($value);
// 生成指向 JavaScript 文件的鏈接
HTML::script($url, $attributes);
// 生成指向 CSS 文件的鏈接
HTML::style($url, $attributes);
// 生成 HTML 圖像元素
HTML::image($url, $alt, $attributes);
// 生成 HTML 鏈接
HTML::link($url, 'title', $attributes, $secure);
// 生成 HTTPS HTML 鏈接
HTML::secureLink($url, 'title', $attributes);
// 生成資產的 HTML 鏈接
HTML::linkAsset($url, 'title', $attributes, $secure);
// 生成指向資產的 HTTPS HTML 鏈接
HTML::linkSecureAsset($url, 'title', $attributes);
// 生成指向命名路由的 HTML 鏈接
HTML::linkRoute($name, 'title', $parameters, $attributes);
// 生成指向控制器操作的 HTML 鏈接
HTML::linkAction($action, 'title', $parameters, $attributes);
// 生成指向電子郵件地址的 HTML 鏈接
HTML::mailto($email, 'title', $attributes);
// 混淆電子郵件地址以防止垃圾郵件機器人嗅探它
HTML::email($email);
// 生成有序的項目列表
HTML::ol($list, $attributes);
// 生成一個未排序的項目列表
HTML::ul($list, $attributes);
// 創建一個列表 HTML 元素
HTML::listing($type, $list, $attributes);
// 為列表元素創建 HTML
HTML::listingElement($key, $type, $value);
// 為嵌套列表屬性創建 HTML
HTML::nestedListing($key, $type, $value);
// 從數組構建 HTML 屬性字符串
HTML::attributes($attributes);
// 構建單個屬性元素
HTML::attributeElement($key, $value);
// 混淆字符串以防止垃圾郵件機器人嗅探它
HTML::obfuscate($value);

DB

基本數據庫使用

DB::connection('connection_name');
// 運行選擇查詢
$results = DB::select('select * from users where id = ?', [1]);
$results = DB::select('select * from users where id = :id', ['id' => 1]);
// 運行一般聲明
DB::statement('drop table users');
// 偵聽查詢事件
DB::listen(function($sql, $bindings, $time){ code_here; });
// 數據庫事務
DB::transaction(function()
{
  DB::table('users')->update(['votes' => 1]);
  DB::table('posts')->delete();
});
DB::beginTransaction();
DB::rollback();
DB::commit();

查詢生成器

// 從表中檢索所有行
DB::table('name')->get();
// 表中的分塊結果
DB::table('users')->chunk(100, function($users)
{
  foreach ($users as $user)
  {  
//
}
});
// 從表中檢索單行
$user = DB::table('users')->where('name', 'John')->first();
DB::table('name')->first();
// 從一行中檢索單個列
$name = DB::table('users')->where('name', 'John')->pluck('name');
DB::table('name')->pluck('column');
// 檢索列值列表
$roles = DB::table('roles')->lists('title');
$roles = DB::table('roles')->lists('title', 'name');
// 指定 Select 子句
$users = DB::table('users')->select('name', 'email')->get();
$users = DB::table('users')->distinct()->get();
$users = DB::table('users')->select('name as user_name')->get();
// 將 Select 子句添加到現有查詢
$query = DB::table('users')->select('name');
$users = $query->addSelect('age')->get();
// 使用 Where 運算符
$users = DB::table('users')->where('votes', '>', 100)->get();
$users = DB::table('users')
              ->where('votes', '>', 100)
              ->orWhere('name', 'John')
              ->get();
$users = DB::table('users')
              ->whereBetween('votes', [1, 100])->get();
$users = DB::table('users')
              ->whereNotBetween('votes', [1, 100])->get();
$users = DB::table('users')
              ->whereIn('id', [1, 2, 3])->get();
$users = DB::table('users')
              ->whereNotIn('id', [1, 2, 3])->get();
$users = DB::table('users')
              ->whereNull('updated_at')->get();
DB::table('name')->whereNotNull('column')->get();
// 動態 Where 子句
$admin = DB::table('users')->whereId(1)->first();
$john = DB::table('users')
              ->whereIdAndEmail(2, 'john@doe.com')
              ->first();
$jane = DB::table('users')
              ->whereNameOrAge('Jane', 22)
              ->first();
// 排序依據、分組依據和擁有
$users = DB::table('users')
              ->orderBy('name', 'desc')
              ->groupBy('count')
              ->having('count', '>', 100)
              ->get();
DB::table('name')->orderBy('column')->get();
DB::table('name')->orderBy('column','desc')->get();
DB::table('name')->having('count', '>', 100)->get();
// 偏移和限制
$users = DB::table('users')->skip(10)->take(5)->get();

Joins

基本加入聲明

DB::table('users')
      ->join('contacts', 'users.id', '=', 'contacts.user_id')
      ->join('orders', 'users.id', '=', 'orders.user_id')
      ->select('users.id', 'contacts.phone', 'orders.price')
      ->get();

左連接語句

DB::table('users')
    ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
    ->get();
// select * from name = 'John' or (votes > 100 and title <> 'Admin')
DB::table('users')
        ->where('name', '=', 'John')
        ->orWhere(function($query)
        {
            $query->where('votes', '>', 100)
                  ->where('title', '<>', 'Admin');
        })
        ->get();

Aggregates

$users = DB::table('users')->count();
$price = DB::table('orders')->max('price');
$price = DB::table('orders')->min('price');
$price = DB::table('orders')->avg('price');
$total = DB::table('users')->sum('votes');

DB::table('name')->remember(5)->get();
DB::table('name')->remember(5, 'cache-key-name')->get();
DB::table('name')->cacheTags('my-key')->remember(5)->get();
DB::table('name')
    ->cacheTags(array('my-first-key','my-second-key'))
    ->remember(5)
    ->get();

原始表達式

$users = DB::table('users')
        ->select(DB::raw('count(*) as user_count, status'))
        ->where('status', '<>', 1)
        ->groupBy('status')
        ->get();
// 返回行
DB::select('select * from users where id = ?', array('value'));
// 返回 nr 個受影響的行
DB::insert('insert into foo set bar=2');
DB::update('update foo set bar=2');
DB::delete('delete from bar');
// 返回無效
DB::statement('update foo set bar=2');
// 語句中的原始表達式
DB::table('name')
        ->select(DB::raw('count(*) as count, column2'))
        ->get();

Inserts 插入

DB::table('users')->insert(
  ['email' => 'john@example.com', 'votes' => 0]
);
$id = DB::table('users')->insertGetId(
  ['email' => 'john@example.com', 'votes' => 0]
);
DB::table('users')->insert([
  ['email' => 'taylor@example.com', 'votes' => 0],
  ['email' => 'dayle@example.com', 'votes' => 0]
]);

Updates 更新

DB::table('users')
          ->where('id', 1)
          ->update(['votes' => 1]);
DB::table('users')->increment('votes');
DB::table('users')->increment('votes', 5);
DB::table('users')->decrement('votes');
DB::table('users')->decrement('votes', 5);
DB::table('users')->increment('votes', 1, ['name' => 'John']);

Deletes 刪除

DB::table('users')->where('votes', '<', 100)->delete();
DB::table('users')->delete();
DB::table('users')->truncate();

Unions 聯合

// unionAll() 方法也可用,并且具有與 union 相同的方法簽名
$first = DB::table('users')->whereNull('first_name');
$users = DB::table('users')->whereNull('last_name')->union($first)->get();
// Pessimistic Locking 悲觀鎖定
DB::table('users')->where('votes', '>', 100)->sharedLock()->get();
DB::table('users')->where('votes', '>', 100)->lockForUpdate()->get();

Input

Input

Input::get('key');
// 如果密鑰丟失則默認
Input::get('key', 'default');
Input::has('key');
Input::all();
// 獲取輸入時僅檢索“foo”和“bar”
Input::only('foo', 'bar');
// 獲取輸入時忽略“foo”
Input::except('foo');
Input::flush();

Session Input (flash)

// 會話的閃存輸入
Input::flash();
// 只閃爍會話的一些輸入
Input::flashOnly('foo', 'bar');
// 只閃爍會話的一些輸入
Input::flashExcept('foo', 'baz');
// 檢索舊輸入項
Input::old('key','default_value');

Files

// 使用已上傳的文件
Input::file('filename');
// 判斷文件是否上傳
Input::hasFile('filename');
// 訪問文件屬性
Input::file('name')->getRealPath();
Input::file('name')->getClientOriginalName();
Input::file('name')->getClientOriginalExtension();
Input::file('name')->getSize();
Input::file('name')->getMimeType();
// 移動上傳的文件
Input::file('name')->move($destinationPath);
// 移動上傳的文件
Input::file('name')->move($destinationPath, $fileName);

路由

Route

Route::get('foo', function(){});
Route::get('foo', 'ControllerName@function');
Route::controller('foo', 'FooController');

RESTful 控制器

Route::resource('posts','PostsController');
// 指定要在路線上處理的動作子集
Route::resource('photo', 'PhotoController',['only' => ['index', 'show']]);
Route::resource('photo', 'PhotoController',['except' => ['update', 'destroy']]);

觸發錯誤

App::abort(404);
$handler->missing(...) in ErrorServiceProvider::boot();

throw new NotFoundHttpException;

路由參數

Route::get('foo/{bar}', function($bar){});
Route::get('foo/{bar?}', function($bar = 'bar'){});

HTTP 動詞

Route::any('foo', function(){});
Route::post('foo', function(){});
Route::put('foo', function(){});
Route::patch('foo', function(){});
Route::delete('foo', function(){});
// RESTful 動作
Route::resource('foo', 'FooController');
// 為多個動詞注冊一個路由
Route::match(['get', 'post'], '/', function(){});

Secure Routes(TBD)

Route::get('foo', array('https', function(){}));

路由約束

Route::get('foo/{bar}', function($bar){})
->where('bar', '[0-9]+');
Route::get('foo/{bar}/{baz}', function($bar, $baz){})
->where(array('bar' => '[0-9]+', 'baz' => '[A-Za-z]'))

// 設置跨路線使用的模式
Route::pattern('bar', '[0-9]+')

HTTP 中間件

// 為路由分配中間件
Route::get('admin/profile', ['middleware' => 'auth', function(){}]);

命名路由

Route::currentRouteName();
Route::get('foo/bar', array('as' => 'foobar', function(){}));
Route::get('user/profile', [
  'as' => 'profile', 'uses' => 'UserController@showProfile'
]);
$url = route('profile');
$redirect = redirect()->route('profile');

路由前綴

Route::group(['prefix' => 'admin'], function()
{
  Route::get('users', function(){
      return 'Matches The "/admin/users" URL';
  });
});

路由命名空間

// 該路由組將攜帶命名空間“Foo\Bar”
Route::group(array('namespace' => 'Foo\Bar'), function(){})

子域路由

// {sub} 將被傳遞給閉包
Route::group(array('domain' => '{sub}.example.com'), function(){});

Model

基本用法

// 定義 Eloquent 模型
class User extends Model {}
// 生成 Eloquent 模型
php artisan make:model User
// 指定自定義表名
class User extends Model {
  protected $table = 'my_users';
}

More

Model::create(array('key' => 'value'));
// 按屬性查找第一個匹配記錄或創建
Model::firstOrCreate(array('key' => 'value'));
// 按屬性查找第一條記錄或實例化
Model::firstOrNew(array('key' => 'value'));
// 創建或更新匹配屬性的記錄,并填充值
Model::updateOrCreate(array('search_key' => 'search_value'), array('key' => 'value'));
// 用屬性數組填充模型,注意批量賦值!
Model::fill($attributes);
Model::destroy(1);
Model::all();
Model::find(1);
// 使用雙主鍵查找
Model::find(array('first', 'last'));
// 如果查找失敗則拋出異常
Model::findOrFail(1);
// 使用雙主鍵查找并在查找失敗時拋出異常
Model::findOrFail(array('first', 'last'));
Model::where('foo', '=', 'bar')->get();
Model::where('foo', '=', 'bar')->first();
// 動態的
Model::whereFoo('bar')->first();
// 如果查找失敗則拋出異常
Model::where('foo', '=', 'bar')->firstOrFail();
Model::where('foo', '=', 'bar')->count();
Model::where('foo', '=', 'bar')->delete();
// 輸出原始查詢
Model::where('foo', '=', 'bar')->toSql();
Model::whereRaw('foo = bar and cars = 2', array(20))->get();
Model::remember(5)->get();
Model::remember(5, 'cache-key-name')->get();
Model::cacheTags('my-tag')->remember(5)->get();
Model::cacheTags(array('my-first-key','my-second-key'))->remember(5)->get();
Model::on('connection-name')->find(1);
Model::with('relation')->get();
Model::all()->take(10);
Model::all()->skip(10);
// 默認 Eloquent 排序方興未艾
Model::all()->orderBy('column');
Model::all()->orderBy('column','desc');

Soft Delete

Model::withTrashed()->where('cars', 2)->get();
// 在結果中包含軟刪除模型
Model::withTrashed()->where('cars', 2)->restore();
Model::where('cars', 2)->forceDelete();
// 強制結果集只包含軟刪除
Model::onlyTrashed()->where('cars', 2)->get();

Events

Model::creating(function($model){});
Model::created(function($model){});
Model::updating(function($model){});
Model::updated(function($model){});
Model::saving(function($model){});
Model::saved(function($model){});
Model::deleting(function($model){});
Model::deleted(function($model){});
Model::observe(new FooObserver);

Eloquent Configuration

// 禁止從模型插入和更新中拋出批量分配異常
Eloquent::unguard();
// 啟用任何拋出批量分配異常的能力
Eloquent::reguard();

Schema

Schema

// 表示需要創建表
Schema::create('table', function($table)
{
  $table->increments('id');
});
// 指定連接
Schema::connection('foo')->create('table', function($table){});
// 將表重命名為給定名稱
Schema::rename($from, $to);
// 表示應該刪除該表
Schema::drop('table');
// 指示如果表存在則應將其刪除
Schema::dropIfExists('table');
// 確定給定表是否存在
Schema::hasTable('table');
// 確定給定表是否具有給定列
Schema::hasColumn('table', 'column');
// 更新現有表
Schema::table('table', function($table){});
// 指示應重命名給定的列
$table->renameColumn('from', 'to');
// 指示應刪除給定的列
$table->dropColumn(string|array);
// 應該用于表的存儲引擎
$table->engine = 'InnoDB';
// 僅適用于 MySQL
$table->string('name')->after('email');

Indexes

$table->string('column')->unique();
$table->primary('column');
// 創建雙主鍵
$table->primary(array('first', 'last'));
$table->unique('column');
$table->unique('column', 'key_name');
// 創建雙唯一索引
$table->unique(array('first', 'last'));
$table->unique(array('first', 'last'), 'key_name');
$table->index('column');
$table->index('column', 'key_name');
// 創建雙索引
$table->index(array('first', 'last'));
$table->index(array('first', 'last'), 'key_name');
$table->dropPrimary('table_column_primary');
$table->dropUnique('table_column_unique');
$table->dropIndex('table_column_index');

Foreign Keys

$table->foreign('user_id')->references('id')->on('users');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'|'restrict'|'set null'|'no action');
$table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade'|'restrict'|'set null'|'no action');
$table->dropForeign('posts_user_id_foreign');

列類型 - 增量

$table->increments('id');
$table->bigIncrements('id');

列類型 - 字符串和文本

$table->char('name', 4);
$table->string('email');
$table->string('name', 100);
$table->text('description');
$table->mediumText('description');
$table->longText('description');

列類型 - 數字

$table->integer('votes');
$table->tinyInteger('votes');
$table->smallInteger('votes');
$table->mediumInteger('votes');
$table->bigInteger('votes');
$table->float('amount');
$table->double('column', 15, 8);
$table->decimal('amount', 5, 2);

列類型 - 日期和時間

$table->date('created_at');
$table->dateTime('created_at');
$table->time('sunrise');
$table->timestamp('added_on');

列類型 - 添加 created_at 和 updated_at 列

$table->timestamps();
$table->nullableTimestamps();

列類型 - 其他

$table->binary('data');
$table->boolean('confirmed');
// 為軟刪除添加 deleted_at 列
$table->softDeletes();
$table->enum('choices', array('foo', 'bar'));
// 添加 remember_token 作為 VARCHAR(100) NULL
$table->rememberToken();
// 添加 INTEGER parent_id 和 STRING parent_type
$table->morphs('parent');
->nullable()
->default($value)
->unsigned()

Mail

Mail

Mail::send('email.view', $data, function($message){});
Mail::send(array('html.view', 'text.view'), $data, $callback);
Mail::queue('email.view', $data, function($message){});
Mail::queueOn('queue-name', 'email.view', $data, $callback);
Mail::later(5, 'email.view', $data, function($message){});
// 將所有電子郵件寫入日志而不是發送
Mail::pretend();

Messages

// 這些可以用在傳遞給 Mail::send() 或 Mail::queue() 的 $message 實例上
$message->from('email@example.com', 'Mr. Example');
$message->sender('email@example.com', 'Mr. Example');
$message->returnPath('email@example.com');
$message->to('email@example.com', 'Mr. Example');
$message->cc('email@example.com', 'Mr. Example');
$message->bcc('email@example.com', 'Mr. Example');
$message->replyTo('email@example.com', 'Mr. Example');
$message->subject('Welcome to the Jungle');
$message->priority(2);
$message->attach('foo\bar.txt', $options);
// 這使用內存中的數據作為附件
$message->attachData('bar', 'Data Name', $options);
// 在消息中嵌入文件并獲取 CID
$message->embed('foo\bar.txt');
$message->embedData('foo', 'Data Name', $options);
// 獲取底層的 Swift Message 實例
$message->getSwiftMessage();

Auth

Authentication

// 判斷當前用戶是否通過認證
Auth::check();
// 獲取當前認證的用戶
Auth::user();
// 獲取當前認證用戶的ID
Auth::id();
// 嘗試使用給定的憑據對用戶進行身份驗證
Auth::attempt(array('email' => $email, 'password' => $password));
// 通過將 true 傳遞給 Auth::attempt() 來“記住我”
Auth::attempt($credentials, true);
// 登錄一個請求
Auth::once($credentials);
// 將用戶登錄到應用程序
Auth::login(User::find(1));
// 將給定的用戶 ID 登錄到應用程序中
Auth::loginUsingId(1);
// 從應用程序中注銷用戶
Auth::logout();
// 驗證用戶的憑據
Auth::validate($credentials);
// 嘗試使用 HTTP Basic Auth 進行身份驗證
Auth::basic('username');
// 執行無狀態 HTTP 基本登錄嘗試
Auth::onceBasic();
// 向用戶發送密碼提醒
Password::remind($credentials, function($message, $user){});

Authorization

// 定義能力
Gate::define('update-post', 'Class@method');
Gate::define('update-post', function ($user, $post) {...});
// 傳遞多個參數
Gate::define('delete-comment', function ($user, $post, $comment) {});

// 檢查能力
Gate::denies('update-post', $post);
Gate::allows('update-post', $post);
Gate::check('update-post', $post);
// 指定一個用戶進行檢查
Gate::forUser($user)->allows('update-post', $post);
// 通過 User 模型,使用 Authorizable trait
User::find(1)->can('update-post', $post);
User::find(1)->cannot('update-post', $post);

// 攔截授權檢查
Gate::before(function ($user, $ability) {});
Gate::after(function ($user, $ability) {});

// 在 Blade 模板中檢查
@can('update-post', $post)
@endcan
// with else
@can('update-post', $post)
@else
@endcan

// 生成策略
php artisan make:policy PostPolicy
// `policy` 輔助函數
policy($post)->update($user, $post)

// 控制器授權
$this->authorize('update', $post);
// for $user
$this->authorizeForUser($user, 'update', $post);

Helper

Arrays

// 將給定的鍵/值對添加到數組中,如果
// 數組中不存在給定的鍵
array_add($array, 'key', 'value');
// 將數組的數組折疊成一個數組
array_collapse($array);
// 將一個數組分成兩個數組。一個有鍵,另一個有值
array_divide($array);
// 用點展平多維關聯數組
array_dot($array);
// 獲取所有給定的數組,除了指定的項目數組
array_except($array, array('key'));
// 返回數組中通過給定真值測試的第一個元素
array_first($array, function($key, $value){}, $default);
// 從數組中剝離鍵
array_flatten($array);
// 使用“點”表示法從給定數組中刪除一個或多個數組項
array_forget($array, 'foo');
// 點符號
array_forget($array, 'foo.bar');
// 使用“點”表示法從數組中獲取項目
array_get($array, 'foo', 'default');
array_get($array, 'foo.bar', 'default');
// 使用“點”表示法檢查給定項是否存在于數組中
array_has($array, 'products.desk');
// 從給定數組中獲取項目的子集
array_only($array, array('key'));
// 返回鍵數組 => 值
array_pluck($array, 'key');
// 從數組中返回并刪除“key”
array_pull($array, 'key');
// 使用“點”表示法將數組項設置為給定值
array_set($array, 'key', 'value');
// 點符號
array_set($array, 'key.subkey', 'value');
// 根據給定閉包的結果對數組進行排序
array_sort($array, function(){});
// 使用 sort 函數對數組進行遞歸排序
array_sort_recursive();
// 使用給定的閉包過濾數組
array_where();
// 數組的第一個元素
head($array);
// 數組的最后一個元素
last($array);

Paths

// 應用程序目錄的完全限定路徑
app_path();
// 獲取公共文件夾的路徑
base_path();
// 應用程序配置目錄的完全限定路徑
config_path();
// 應用程序數據庫目錄的完全限定路徑
database_path();
// 獲取版本控制的 Elixir 文件的路徑:
elixir();
// 公共目錄的完全限定路徑
public_path();
// 獲取存儲文件夾的路徑
storage_path();

Miscellaneous

// 驗證器實例(Auth)
auth()->user();
// 生成對用戶先前位置的重定向響應
back();
// 使用 Bcrypt (Hash) 散列給定值
bcrypt('my-secret-password');
// 從提供的項目創建一個集合實例
collect(['taylor', 'abigail']);
// 獲取配置變量的值
config('app.timezone', $default);
// 生成包含 CSRF 令牌值的 HTML 隱藏輸入字段
{!! csrf_field() !!}
// 檢索當前 CSRF 令牌的值
$token = csrf_token();
// 轉儲給定的變量并結束腳本的執行
dd($value);
// 獲取環境變量的值或返回默認值
$env = env('APP_ENV');
$env = env('APP_ENV', 'production');
// 將給定事件分派給它的偵聽器:
event(new UserRegistered($user));
// 為給定類創建模型工廠構建器
$user = factory(App\User::class)->make();
// 生成一個 HTML 隱藏輸入字段,其中包含表單的 HTTP 謂詞的欺騙值
{!! method_field('delete') !!}
// 檢索閃存到會話中的舊輸入值
$value = old('value');
$value = old('value', 'default');
// 返回重定向器的實例以進行重定向:
return redirect('/home');
// 返回當前請求實例或獲取輸入項
$value = request('key', $default = null)
// 創建響應實例或獲取響應工廠的實例
return response('Hello World', 200, $headers);
// 用于獲取/設置會話值
$value = session('key');
$value = session()->get('key');
session()->put('key', $value);
// 將簡單地返回給定的值。
value(function(){ return 'bar'; });
// 檢索視圖實例
return view('auth.login');
// 返回給定的值
$value = with(new Foo)->work();

Strings

// 將值轉換為駝峰大小寫
camel_case($value);
// 獲取給定對象/類的類“basename”
class_basename($class);
// 轉義字符串
e('<html>');
// 確定給定字符串是否以給定子字符串開頭
starts_with('Foo bar.', 'Foo');
// 確定給定字符串是否以給定子字符串結尾
ends_with('Foo bar.', 'bar.');
// 將字符串轉換為蛇形大小寫
snake_case('fooBar');
// 限制字符串中的字符數
str_limit();
// 確定給定的字符串是否包含給定的子字符串
str_contains('Hello foo bar.', 'foo');
// 結果:foo/bar/
str_finish('foo/bar', '/');
str_is('foo*', 'foobar');
str_plural('car');
str_random(25);
str_singular('cars');
str_slug("Laravel 5 Framework", "-");
// 結果:FooBar
studly_case('foo_bar');
trans('foo.bar');
trans_choice('foo.bar', $count);
action('FooController@method', $parameters);
// HTML Link
asset('img/photo.jpg', $title, $attributes);
// HTTPS link
secure_asset('img/photo.jpg', $title, $attributes);
route($route, $parameters, $absolute = true);
url('path', $parameters = array(), $secure = null);

另見