http://homestead.test/
cd C:\Users\Administrator\Homestead
vagrant up
vagrant ssh
vagrant halt

启动失败
C:\Users\Administrator\VirtualBox VMs\homestead-7
homestead-7.vbox

vagrant reload --provision 重新加载Homestead.yaml
vagrant destroy –force 销毁该

cd /etc/nginx/
cat nginx.conf
cd sites-enabled/
sudo cp homestead.test test.test
sudo vim test.test
sudo service nginx reload

composer install
php artisan key:generate
php artisan migrate:fresh
php artisan db:seed
php artisan tinker

中文镜像
composer config -g repo.packagist composer https://packagist.laravel-china.org
取消
composer config -g --unset repos.packagist

php artisan make:controller PhotoController --resource
Route::resource('photos', 'PhotoController');
单个行为控制器
php artisan make:controller ShowProfile --invokable

路由缓存
php artisan route:cache

request
$uri = $request->path();
$request->is('admin/*')
$request->url();
$request->fullUrl();
$request->method();
$request->isMethod('post');
$request->all();
$request->input('name');
$request->query('name');
$request->only(['username', 'password']);
$request->except(['credit_card']);
$request->has('name') //是否存在
$request->filled('name') //是否存在值并且不为空
$request->flash(); //将当前输入的数据存进 session 中
$request->flashOnly(['username', 'email']);
$request->flashExcept('password');
redirect('form')->withInput();//闪存输入后重定向
$request->old('username');
$request->file('photo');
$request->hasFile('photo')
$request->file('photo')->isValid()
$request->photo->path();
$request->photo->extension();
$path = $request->photo->store('images');
$path = $request->photo->store('images', 's3');
$path = $request->photo->storeAs('images', 'filename.jpg');
$path = $request->photo->storeAs('images', 'filename.jpg', 's3');

back 函数的路由使用 web 中间件组或所有 Session 中间件
back()->withInput();
redirect()->route('login'); //重定向至命名路由
redirect()->route('profile', ['id' => 1]);
redirect()->route('profile', [$user]);
redirect()->action('HomeController@index'); //重定向至控制器行为
return redirect()->action(

'UserController@profile', ['id' => 1]

);
redirect()->away('https://www.google.com'); //重定向到外部域
redirect('dashboard')->with('status', 'Profile updated!'); //重定向并使用闪存的 Session 数据
response()->view('hello', $data, 200)->header('Content-Type', $type); //视图响应
return response()->json([

'name' => 'Abigail',
'state' => 'CA'

]); ///JSON 响应
return response()

->json(['name' => 'Abigail', 'state' => 'CA'])
->withCallback($request->input('callback')); // JSONP 响应

response()->download($pathToFile, $name, $headers); //文件下载
return response()->streamDownload(function () {

echo GitHub::api('repo')
            ->contents()
            ->readme('laravel', 'laravel')['contents'];

}, 'laravel-readme.md');
response()->file($pathToFile, $headers);

判断视图文件是否存在
use Illuminate\Support\Facades\View;
if (View::exists('emails.customer')) {

//

}

服务注入
@inject('metrics', 'App\Services\MetricsService')

Monthly Revenue: {{ $metrics->monthlyRevenue() }}.

拓展 Blade
Blade::directive('datetime', function ($expression) {

return "<?php echo ($expression)->format('m/d/Y H:i'); ?>";

});
@datetime($var)

Blade::if('env', function ($environment) {

return app()->environment($environment);

});
@env('local')

// The application is in the local environment...

@else

// The application is not in the local environment...

@endenv

lang
echo __('I love programming.');
{{ __('messages.welcome') }}
@lang('messages.welcome')

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);

Route::match(['get', 'post'], '/', function () {

//

});

Route::any('foo', function () {

//

});

重定向路由
Route::redirect('/here', '/there', 301);

全局约束
如果你希望某个具体的路由参数都遵循同一个正则表达式的约束,就使用 pattern 方法在 RouteServiceProvider 的 boot 方法中定义这些模式:
Route::pattern('id', '[0-9]+');

Route::get('user/{id}/profile', function ($id) {

return 'test'.$id;

})->name('profile');
Route::get('tester/{id?}',function($id=0){

return redirect()->route('profile',['id'=>$id]);

})->where('id', '[0-9]+');

标签: none

添加新评论