
laraval框架
kld230
这个作者很懒,什么都没留下…
展开
-
Laravel 速查表 Artisan
// 针对命令显示帮助信息php artisan --help OR -h// 抑制输出信息php artisan --quiet OR -q// 打印 Laravel 的版本信息php artisan --version OR -V// 不询问任何交互性的问题php artisan --no-interaction OR -n// 强制输出 ANSI 格式php artisa...转载 2019-06-09 10:38:36 · 568 阅读 · 0 评论 -
Laravel 速查表 Input
Input::get('key');// 指定默认值Input::get('key', 'default');Input::has('key');Input::all();// 只取回 'foo' 和 'bar',返回数组Input::only('foo', 'bar');// 取除了 'foo' 的所有用户输入数组Input::except('foo');Input::flu...转载 2019-06-12 15:03:48 · 396 阅读 · 0 评论 -
Laravel 速查表 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');// ...转载 2019-06-12 15:04:12 · 219 阅读 · 0 评论 -
Laravel 速查表 Blade
// 输出内容,被转义过的{{ $var }}// 输出未转义内容{!! $var !!}{{-- Blade 注释,不会被输出到页面中 --}}// 三元表达式的简写,以下相当于「$name ? $name : 'Default'」{{ $name or 'Default' }}{{ $name ?? 'Default' }}// 等同 echo json_encode($ar...转载 2019-06-12 15:04:29 · 1044 阅读 · 0 评论 -
Laravel 速查表 Helper
注:数组和字串函数将在 5.9 全面废弃,推荐使用 Arr 和 Str Facade数组 & 对象// 如果给定的键不存在于该数组,Arr::add 函数将给定的键值对加到数组中Arr::add(['name' => 'Desk'], 'price', 100); // >>> ['name' => 'Desk', 'price' => 1...转载 2019-06-12 15:04:51 · 310 阅读 · 0 评论 -
Laravel 速查表 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...转载 2019-06-12 15:05:10 · 313 阅读 · 0 评论 -
Laravel 速查表 Auth
用户认证// 获取 Auth 对象,等同于 Auth Facadeauth();// 判断当前用户是否已认证(是否已登录)Auth::check();// 判断当前用户是否未登录,与 check() 相反Auth::guest();// 获取当前的认证用户Auth::user();// 获取当前的认证用户的 ID(未登录情况下会报错)Auth::id();// 通过给定的...转载 2019-06-12 15:05:24 · 673 阅读 · 0 评论 -
Laravel 速查表 Schema
// 创建指定数据表 Schema::create('table', function($table){ $table->increments('id');});// 指定一个连接 Schema::connection('foo')->create('table', function($table){});// 通过给定的名称来重命名数据表 Schema::rena...转载 2019-06-12 15:05:48 · 2666 阅读 · 0 评论 -
Laravel 速查表 Security
哈希Hash::make('secretpassword');Hash::check('secretpassword', $hashedPassword);Hash::needsRehash($hashedPassword);加密解密Crypt::encrypt('secretstring');Crypt::decrypt($encryptedString);Crypt::...转载 2019-06-12 15:06:01 · 168 阅读 · 0 评论 -
Laravel 速查表 Event
// 1. EventServiceProvider 类里的 $listen 属性protected $listen =['App\Events\OrderShipped' => ['App\Listeners\SendShipmentNotification']];// 2. 生成监听类php artisan event:generate// 触发命令Event::fire(...转载 2019-06-12 15:06:16 · 391 阅读 · 0 评论 -
Laravel 速查表 Composer
composer create-project laravel/laravel folder_namecomposer create-project laravel/laravel folder_name --prefer-dist "5.8.*"composer installcomposer install --prefer-distcomposer updatecomposer ...转载 2019-06-12 15:06:34 · 194 阅读 · 0 评论 -
Laravel 速查表 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 的别名tran...转载 2019-06-13 13:40:25 · 535 阅读 · 0 评论 -
Laravel 速查表 Environment
$environment = app()->environment();$environment = App::environment();// 判断当环境是否为 localif (app()->environment('local')){}// 判断当环境是否为 local 或 staging...if (app()->environment(['local', '...转载 2019-06-13 13:40:42 · 828 阅读 · 0 评论 -
Laravel 速查表 SSH
Executing CommandsSSH::run(array $commands);// 指定 remote, 否则将使用默认值SSH::into($remote)->run(array $commands);SSH::run(array $commands, function($line){ echo $line.PHP_EOL;});任务// 定义任务...转载 2019-06-13 13:40:54 · 241 阅读 · 0 评论 -
Laravel 速查表 Route
RouteRoute::get('foo', function(){});Route::get('foo', 'ControllerName@function');Route::controller('foo', 'FooController');资源路由Route::resource('posts','PostsController');// 资源路由器只允许指定动作通过...转载 2019-06-10 09:34:17 · 1596 阅读 · 0 评论 -
Laravel 速查表 Pagination
// 自动处理分页逻辑Model::paginate(15);Model::where('cars', 2)->paginate(15);// 使用简单模板 - 只有 "上一页" 或 "下一页" 链接Model::where('cars', 2)->simplePaginate(15);// 手动分页Paginator::make($items, $totalItems,...转载 2019-06-10 09:34:04 · 700 阅读 · 0 评论 -
Laravel 速查表 Queue
Queue::push('SendMail', array('message' => $message));Queue::push('SendEmail@send', array('message' => $message));Queue::push(function($job) use $id {});// 在多个 workers 中使用相同的负载 Queue::bulk(...转载 2019-06-10 09:33:32 · 568 阅读 · 0 评论 -
Laravel 速查表 Model
基础使用// 定义一个 Eloquent 模型class User extends Model {}// 生成一个 Eloquent 模型php artisan make:model User// 生成一个 Eloquent 模型的时候,顺便生成迁移文件php artisan make:model User --migration OR -m// 指定一个自定义的数据表名称c...转载 2019-06-09 10:40:32 · 598 阅读 · 0 评论 -
Laravel 速查表 Log
// 记录器提供了 7 种在 RFC 5424 标准内定义的记录等级:// debug, info, notice, warning, error, critical, and alert.Log::info('info');Log::info('info',array('context'=>'additional info'));Log::error('error');Log:...转载 2019-06-09 10:41:24 · 468 阅读 · 0 评论 -
Laravel 速查表 URL
URL::full();URL::current();URL::previous();URL::to('foo/bar', $parameters, $secure);URL::action('NewsController@item', ['id'=>123]);// 需要在适当的命名空间内URL::action('Auth\AuthController@logout');U...转载 2019-06-09 10:42:25 · 150 阅读 · 0 评论 -
Laravel 速查表 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]);// 运...转载 2019-06-09 10:43:02 · 2509 阅读 · 0 评论 -
Laravel 速查表 Cookie
// 等于 Cookiecookie();request()->cookie('name');Cookie::get('key');Cookie::get('key', 'default');// 创建一个永久有效的 cookieCookie::forever('key', 'value');// 创建一个 N 分钟有效的 cookieCookie::make('key',...转载 2019-06-09 10:44:01 · 119 阅读 · 0 评论 -
Laravel 速查表 Cache
// 获取缓存对象,约等于 Cachecache()// 注意 5.8 缓存单位为「秒」,之前版本为「分」Cache::put('key', 'value', $seconds);// 未设置过期时间将永久有效Cache::put('key', 'value'); Cache::add('key', 'value', $seconds);Cache::forever('key',...原创 2019-06-09 10:45:26 · 1650 阅读 · 0 评论 -
Laravel 速查表 Request
//获取请求参数 form-data 与 raw 请求类型request()->input();// url: http://xx.com/aa/bbRequest::url();// 路径: /aa/bbRequest::path();// 获取请求 Uri: /aa/bb/?c=dRequest::getRequestUri();// 返回用户的 IPRequest:...转载 2019-06-09 10:46:00 · 593 阅读 · 0 评论 -
Laravel 速查表 Response
return Response::make($contents);return Response::make($contents, 200);return Response::json(array('key' => 'value'));return Response::json(array('key' => 'value'))->setCallback(Input::g...转载 2019-06-09 10:46:36 · 429 阅读 · 0 评论 -
Laravel 速查表 Validation
Validator::make(array('key' => 'Foo'),array('key' => 'required|in:Foo'));Validator::extend('foo', function($attribute, $value, $params){});Validator::extend('foo', 'FooValidator@validate')...转载 2019-06-10 09:30:15 · 242 阅读 · 0 评论 -
Laravel 速查表 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(...转载 2019-06-10 09:31:02 · 753 阅读 · 0 评论 -
Laravel 速查表 File
File::exists($path);File::get($path, $lock = false);// 加锁读取文件内容File::sharedGet($path);// 获取文件内容,不存在会抛出 FileNotFoundException 异常File::getRequire($path);// 获取文件内容, 仅能引入一次File::requireOnce($file)...转载 2019-06-10 09:31:46 · 589 阅读 · 0 评论 -
Laravel 速查表 Collection
// 创建集合collect([1, 2, 3]);// 返回该集合所代表的底层数组:$collection->all();// 返回集合中所有项目的平均值:collect([1, 1, 2, 4])->avg() // 2$collection->average();// 将集合拆成多个给定大小的较小集合:collect([1, 2, 3, 4, 5])-&g...转载 2019-06-10 09:32:53 · 1211 阅读 · 0 评论 -
Laravel 速查表 Storage
// 写入文件Storage::put('avatars/1', $fileContents);// 指定磁盘Storage::disk('local')->put('file.txt', 'Contents');Storage::get('file.jpg');Storage::exists('file.jpg');Storage::download('file.jpg', ...转载 2019-06-10 09:33:19 · 2852 阅读 · 0 评论 -
Laravel 速查表 UnitTest
安装和运行// 将其加入到 composer.json 并更新:composer require "phpunit/phpunit:4.0.*"// 运行测试 (在项目根目录下运行)./vendor/bin/phpunit断言$this->assertTrue(true);$this->assertEquals('foo', $bar);$this->a...转载 2019-06-13 13:41:06 · 259 阅读 · 0 评论