Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
ย
All Aboard for Laravel 5.1
1. All Aboard for Laravel 5.1
Jason McCreary
"JMac"
@gonedark
2. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
A short rant about frameworks
Choose wisely and code carefully
2
3. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Talk the Talk
1. Whatโs New in Laravel 5.0
2. Upgrading from Laravel 4.2
3. Whatโs New in Laravel 5.1
4. Whatโs coming in Laravel 5.2
3
4. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
The Goal
โTo get you familiar with the new features in Laravel so
you are comfortable upgrading your projects to 5.1โ
4
5. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Why Upgrade?
โLaravel 5.1 is the ๏ฌrst release of Laravel to receive
long term support. Laravel 5.1 will receive bug ๏ฌxes
for 2 years and security ๏ฌxes for 3 years.This support
window is the largest ever provided for Laravel and
provides stability and peace of mind for larger,
enterprise clients and customers.โ
5
6. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Whatโs Newโฆ
In Laravel 5.0
6
7. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
New Folder Structure
โข Follows PSR-4 naming conventions
โข App namespacing
โข Models live in the default namespace
โข Everything related to HTTP lives under Http/
(controllers, middleware, requests)
โข Views live outside the App namespace within
resources/.
7
8. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Folder Structure
8
4.2 5.0
9. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
App Folder
9
4.2 5.0
10. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Namespacing
<?php namespace App;โจ
โจ
// ...
โจ
class User extends Model {โจ
// ...โจ
}
10
11. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Namespacing
<?php namespace AppHttpControllers;โจ
โจ
class HomeController extends Controller {
โจ
public function index()โจ
{โจ
return view('home');โจ
}โจ
}
11
13. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
New Objects
โข Events are now objects, not strings!
โข Command objects allow simpler job processing
โข Requests are now objects
โข Middleware objects to replace Filters
13
14. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Middleware
โHTTP middleware provide a convenient mechanism
for ๏ฌltering HTTP requests entering your application.โ
14
15. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Middleware
<?php namespace AppHttpControllers;โจ
โจ
class HomeController extends Controller {โจ
public function __construct()โจ
{โจ
$this->middleware('auth');โจ
}
// ...โจ
}
15
16. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Middleware
<?php namespace AppHttpMiddleware;
use Closure;
class TimeoutMiddleware {
public function handle($request, Closure $next) {
if (abs(time() - $request->input(โttlโ)) > 300) {
return redirect('timeout');
}
return $next($request);
}
}
16
17. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Form Request Objects
โA simple way to customize request validation
automatically.โ
17
18. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Form Request Objects
<?php namespace AppHttpRequests;
class RegisterRequest extends FormRequest {
public function rules() {
return [
'email' => 'required|email|unique:users',
'password' => 'required|confirmed|min:8'
];
}
}
18
19. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Controller Method Injection
โIn addition to constructor injection, you may now
type-hint dependencies on controller methods. These
objects will be resolved and available along with any
route parameters.โ
19
20. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Controller Method Injection
public function register(
RegisterRequest $request,
RegistrationRepository $registration)
{
// ...
}
20
21. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
ControllerValidation
"If FormRequests are a little too much, the Laravel 5
base controller now includes a
ValidatesRequests trait.This trait provides a
simple validate() method to validate incoming
requests."
21
22. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
ControllerValidation
public function register(Request $request)
{
$this->validate($request, [
'email' => 'required|email|unique:users',
'password' => 'required|confirmed|min:8'
]);
}
22
23. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Environment Con๏ฌguration
โLaravel 5 uses the DotEnv library to condense all
con๏ฌguration values into a single .env ๏ฌle. These
values get loaded into $_ENV and available through the
env() helper method.โ
23
26. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Artisan Updates
โข Now includes several make commands to generate
common objects
โข tinker is now backed by Psysh for a more powerful
REPL
โข route commands for listing and caching routes
26
27. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Authentication
โUser registration, authentication, and password reset
controllers are now included out of the box, as well as
simple corresponding views.โ
27
28. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
User Model (4.2)
<?phpโจ
โจ
use IlluminateAuthUserTrait;โจ
use IlluminateAuthUserInterface;โจ
use IlluminateAuthRemindersRemindableTrait;โจ
use IlluminateAuthRemindersRemindableInterface;โจ
โจ
class User extends Eloquent implements UserInterface,
RemindableInterface {โจ
โจ
use UserTrait, RemindableTrait;โจ
โจ
protected $table = 'users';โจ
protected $hidden = array('password', 'remember_token');โจ
}
28
29. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
User Model (5.0)
<?php namespace App;โจ
โจ
use IlluminateAuthAuthenticatable;โจ
use IlluminateDatabaseEloquentModel;โจ
use IlluminateAuthPasswordsCanResetPassword;โจ
use IlluminateContractsAuthAuthenticatable as AuthenticatableContract;โจ
use IlluminateContractsAuthCanResetPassword as
CanResetPasswordContract;โจ
โจ
class User extends Model implements AuthenticatableContract,
CanResetPasswordContract {โจ
โจ
use Authenticatable, CanResetPassword;โจ
โจ
protected $table = 'users';โจ
protected $fillable = ['name', 'email', 'password'];โจ
protected $hidden = ['password', 'remember_token'];โจ
}
29
30. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Blade
โBy default, Laravel 5.0 escapes all output from both
the {{ }} and {{{ }}} Blade directives. A new
{!! !!} directive has been introduced to display raw,
unescaped output.โ
30
31. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Libraries and Packages
โข Laravel Elixir - asset management
โข Laravel Socialite - authentication with Oauth services
โข Flysystem - ๏ฌlesystem abstraction library
โข Laravel Scheduler - command manager
31
32. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Upgrading Laravel
From 4.2 to 5.0
32
33. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Two Approaches
โข โNew move-inโ
โข โUpdate in-placeโ
33
34. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
What to do?
โAs always, it depends. However, the documentation
recommends migrating your 4.2 app to a new Laravel 5
app. So, new move-in it is.โ
34
35. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Basic Steps
1. Create a new Laravel 5 app
2. Migrate con๏ฌguration
3. Move app ๏ฌles
4. Add namespacing
5. Review Bindings
6. Miscellaneous changes
7. Blade Tag changes
8. Update dependencies
9. Cross ๏ฌngers
35
36. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Do not pass 5.0!
โGoing directly to 5.1 will make the migration more
complicated as there are signi๏ฌcant changes between
5.0 and 5.1. Do not pass 5.0. Otherwise you will not
collect $200 and you will go to jail.โ
36
37. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Create new Laravel 5 app
composer create-project laravel/laravel --prefer-dist
37
38. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Create new Laravel 5 app
composer global require โlaravel/installer=~1.1โ
laravel new project-name
38
39. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Migrate Con๏ฌguration
1. Copy con๏ฌguration from your 4.2 appโs env.php
to .env
2. Compare con๏ฌgurations from your 4.2 appโs
config/
3. Recreate environment con๏ฌgurations from your 4.2
appโs config/env/ to.env
4. Update environment con๏ฌgurations to use env()
39
40. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Migrate Con๏ฌguration
โBe sure to leave .env.example ๏ฌle in your project.
It should contain placeholder values that will make it
easy for other developers to copy and con๏ฌgure for
their environment.โ
40
41. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Migrate Con๏ฌguration
โWhen managing multiple environments, you may ๏ฌnd it
easiest to create several .env ๏ฌles and symlink
the .env within each environment.โ
41
42. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Move Files
42
4.2 5.0
43. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Move Files
โข routes.php to app/Http/routes.php
โข app/views to resources/views
โข app/database to database/
43
44. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Add namespace
โYou do not need to do this.You can keep everything in
the global namespace and add the paths to the
classmap just as in Laravel 4.2. However, not doing
so carries over technical debt as your project will not
truly follow Laravel 5.0โs con๏ฌguration.โ
44
45. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Add namespace
<?php namespace AppHttpControllers;โจ
โจ
class YourController extends Controller {
// ...โจ
}โจ
45
46. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Add namespace
<?php namespace App;โจ
โจ
class YourModel extends Eloquent {
// ...โจ
}โจ
46
47. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Review Bindings
"Move any service container bindings from start/
global.php to the register method of the app/
Providers/AppServiceProvider.php ๏ฌle."
47
48. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Miscellaneous Changes
โขSoftDeletingTrait is now SoftDeletes
โขUser Authentication changes
โขPagination method changes
โขOh yeah, and the Form and Html Facades are gone.
48
49. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Blade Changes
1. Cry
2. Bargain
3. Face reality
4. Start changing every {{ }} to {!! !!}
5. Remove all blade comment tags {{-- --}} (you
should have known better)
6. Smile
49
50. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Update your dependencies
"Review your dependencies then run composer
update"
50
51. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Cross ๏ฌngers
51
52. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 201552
53. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Questionsโฆ
Ask now! Cause weโre moving to 5.1
53
54. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Whatโs Newโฆ
In Laravel 5.1
54
55. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Project Updates
โข Long Term Support
โข Requires PHP > 5.5.9
โข Follows PSR-2
โข Updated Documentation
โข Uses openssl for encryption, instead of mcrypt
55
56. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
App Folder
56
5.0 5.1
57. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Event Broadcasting
"makes it easy to broadcast your events over a
websocket connection."
57
58. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Middleware Parameters
<?php namespace AppHttpMiddleware;
use Closure;
class RoleMiddleware {
public function handle($request, Closure $next, $role) {
if (!$request->user()->hasRole($role)) {
// Redirect...
}
return $next($request);
}
}
58
59. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Middleware Parameters
Route::put(
โpost/{id}',
['middleware' => 'role:editor', function ($id) {
// ...
}]
);
59
60. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Focus on Testing
โข Stronger integration testing
โข Model factories
60
61. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Whatโs Comingโฆ
In Laravel 5.2
61
62. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Laravel 5.2
โข Coming December 2015
โข Route ๏ฌlters have been deprecated in preference of
middleware.
โข *_fetch methods deprecated in favor of *_pluck
62
63. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Resources
โข Whatโs new in Laravel 5 Laracasts
โข Laravel Of๏ฌcial Upgrade Guide
โข Laravel In-Place Upgrade Guide
โข Whatโs new in Laravel 5.1 Laracasts
63
64. All Aboard for Laravel 5.1 - Jason McCreary - php[world] 2015
Questionsโฆ
@gonedark on Twitter
64