This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1100 lines (815 loc) · 76.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Alex's Blog</title>
<meta name="author" content="Alex Russell">
<meta name="description" content="15th December 2013 Code, Laravel, Laravel Digest Laravel Digest (December 2013) Welcome to the fourth instalment of Laravel Digest, the series where …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/atom.xml" rel="alternate" title="Alex's Blog" type="application/atom+xml">
<link rel="canonical" href="http://alexrussell.me.uk/">
<link href="/favicon.png" rel="shortcut icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="/stylesheets/font-awesome.min.css" media="screen, projection" rel="stylesheet" type="text/css">
<!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,700' rel='stylesheet' type='text/css'>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-45080124-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div class="container">
<div class="left-col">
<div class="intrude-less">
<header id="header" class="inner"><div class="profilepic">
<img src="http://www.gravatar.com/avatar/40b8a76ccad69f24259200911d760abe?s=160" alt="Profile Picture" style="width: 160px;" />
</div>
<hgroup>
<h1><a href="/">Alex's Blog</a></h1>
</hgroup>
<nav id="main-nav"><section class="about-me">
<p>Web developer from Birmingham, UK working at <a href="http://clevercherry.com/">clevercherry</a>.</p>
<p>The opinions in this blog are my own naïve idealistic opinions and not the opinions of my employer.</p>
</section>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/laravel-cheat-sheet/">Laravel Cheat Sheet</a></li>
<li><a href="/blog/archives">Archives</a></li>
</ul>
</nav>
<nav id="sub-nav">
<div class="social">
<a class="twitter" href="http://twitter.com/alexrussell101" title="Twitter">Twitter</a>
<a class="github" href="https://github.com/alexrussell" title="GitHub">GitHub</a>
<a class="rss" href="/atom.xml" title="RSS">RSS</a>
</div>
</nav>
</header>
</div>
</div>
<div class="mid-col">
<div class="mid-col-container">
<div id="content" class="inner">
<div itemscope itemtype="http://schema.org/Blog">
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-12-15T10:00:00+00:00" data-updated="true" itemprop="datePublished">15<span>th</span> December 2013</time></div>
<div class="tags">
<a class='category' href='/blog/categories/code/'>Code</a>, <a class='category' href='/blog/categories/laravel/'>Laravel</a>, <a class='category' href='/blog/categories/laravel-digest/'>Laravel Digest</a>
</div>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/12/laravel-digest-december-2013/" itemprop="url">Laravel Digest (December 2013)</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>Welcome to the fourth instalment of Laravel Digest, the series where I give a regular rundown of important changes, fixes and additions to Laravel’s master branch. Due to the release of Laravel 4.1 I’ve decided to bring this post forward to match the status of Laravel on the day(ish) of release. As such, below are the changes up to the middle of December 2013:</p>
<ul>
<li><code>Collection#first</code> can now have a closure (and default) passed to it that will be passed into a <code>array_first</code>-like call (<a href="https://github.com/laravel/framework/commit/d600ebe7c2e76ca98c5ed280d77107a4159acfc4"><code>d600ebe</code></a>):</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// get all users</span>
</span><span class='line'><span class="nv">$users</span> <span class="o">=</span> <span class="nx">User</span><span class="o">::</span><span class="na">all</span><span class="p">();</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// get first that is enabled or string 'None' if none match</span>
</span><span class='line'><span class="nv">$firstEnabled</span> <span class="o">=</span> <span class="nv">$users</span><span class="o">-></span><span class="na">first</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="nv">$key</span><span class="p">,</span> <span class="nv">$model</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="nv">$model</span><span class="o">-></span><span class="na">enabled</span> <span class="o">==</span> <span class="mi">1</span><span class="p">;</span>
</span><span class='line'><span class="p">},</span> <span class="s1">'None'</span><span class="p">);</span> <span class="c1">// obviously an awful example in terms of what it returns</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p>New <code>array_last</code> helper (side-effect of some other work which was reverted) that works the same as array_first (<a href="https://github.com/laravel/framework/commit/88421ddc6b2313ec16cd65b66a03ee8258e02702"><code>88421dd</code></a>)</p></li>
<li><p><code>Collection#sortBy</code> now takes <a href="http://www.php.net/manual/en/function.sort.php">sort flags</a> as its second parameter (<a href="https://github.com/laravel/framework/commit/426c9e0e39915eedd2861b147ba6701443136e3d"><code>426c9e0</code></a>)</p></li>
<li><p>You can now retrieve failed recipients to <code>Mail::send()</code> with <code>Mail::failures()</code> (<a href="https://github.com/laravel/framework/commit/a0086a5779c21a06def56d9cff9bb51a3ed3f242">a0086a5</a>)</p></li>
<li><p><code>Model::destroy()</code> now returns the number of rows that were deleted (<a href="https://github.com/laravel/framework/commit/0f1a3cce2c08cee6fcea5fd754efe54b1130f4db"><code>0f1a3cc</code></a>)</p></li>
<li><p>There’s also a bunch of new documentation for all the new features I’ve spoken about:</p>
<ul>
<li><a href="http://laravel.com/docs/upgrade">Upgrade guide</a></li>
<li><a href="http://laravel.com/docs/security#password-reminders-and-reset">New password reminder system</a></li>
<li><a href="http://laravel.com/docs/cache#cache-tags">Cache tags</a></li>
<li>Queues had a number of changes, the most important being logging of failed jobs. So <a href="http://laravel.com/docs/queues#failed-jobs">its documentation</a> should be looked over.</li>
<li>A <a href="http://laravel.com/docs/ssh">new SSH module</a> was incorporated primarily for interacting with a live environment (for example, deployment or tailing remote logs).</li>
<li><a href="http://laravel.com/docs/templates#other-blade-control-structures">New Blade features</a></li>
<li><code>Validator#sometimes()</code> <a href="http://laravel.com/docs/validation#conditionally-adding-rules">documentation</a></li>
<li>Database <a href="http://laravel.com/docs/database#read-write-connections">read/write connection splitting</a></li>
<li>Database query builder got <a href="http://laravel.com/docs/queries">some extra methods as pessimistic locking</a>.</li>
<li>Eloquent relationships had a few updates too:
<ul>
<li><a href="http://laravel.com/docs/eloquent#has-many-through">hasManyThrough</a></li>
<li><a href="https://github.com/laravel/docs/pull/547">Polymorphic many-to-many()</a> (not yet in official documentation)</li>
<li><a href="http://laravel.com/docs/eloquent#querying-relations">Model::has() and Model:whereHas()</a></li>
<li><a href="http://laravel.com/docs/eloquent#eager-loading">Eager loading constraints</a> (scroll down a little)</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-12-01T10:00:00+00:00" data-updated="true" itemprop="datePublished">1<span>st</span> December 2013</time></div>
<div class="tags">
<a class='category' href='/blog/categories/code/'>Code</a>, <a class='category' href='/blog/categories/laravel/'>Laravel</a>, <a class='category' href='/blog/categories/laravel-digest/'>Laravel Digest</a>
</div>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/12/laravel-digest-november-2013/" itemprop="url">Laravel Digest (November 2013)</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>Welcome to the third instalment of Laravel Digest, the series where I give a regular rundown of important changes, fixes and additions to Laravel’s master branch. Below are the changes up to the end of November 2013:</p>
<ul>
<li>Relationships can now reference any key on the parent model using a new last parameter for each of the <code>\Eloquent\Model</code> methods (<code>belongsTo</code>: <a href="https://github.com/laravel/framework/commit/c7d2740404251d9e08a24eacbbc42812b038fbaa"><code>c7d2740</code></a>, <code>hasOne</code>, <code>hasMany</code>, morph relationships: <a href="https://github.com/laravel/framework/commit/a634f4a634f457860c8ac7c091da4912351dcdc29562c15"><code>a634f45</code></a>):</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">User</span> <span class="k">extends</span> <span class="nx">Eloquent</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'> <span class="c1">// belongsTo</span>
</span><span class='line'> <span class="k">public</span> <span class="k">function</span> <span class="nf">group</span><span class="p">()</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="nv">$this</span><span class="o">-></span><span class="na">belongsTo</span><span class="p">(</span><span class="s1">'Group'</span><span class="p">,</span> <span class="s1">'group'</span><span class="p">,</span> <span class="s1">'name'</span><span class="p">);</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="c1">// hasOne</span>
</span><span class='line'> <span class="k">public</span> <span class="k">function</span> <span class="nf">city</span><span class="p">()</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="nv">$this</span><span class="o">-></span><span class="na">hasOne</span><span class="p">(</span><span class="s1">'City'</span><span class="p">,</span> <span class="s1">'city'</span><span class="p">,</span> <span class="s1">'name'</span><span class="p">);</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="c1">// hasMany</span>
</span><span class='line'> <span class="k">public</span> <span class="k">function</span> <span class="nf">roles</span><span class="p">()</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="nv">$this</span><span class="o">-></span><span class="na">hasMany</span><span class="p">(</span><span class="s1">'Role'</span><span class="p">,</span> <span class="s1">'role'</span><span class="p">,</span> <span class="s1">'type'</span><span class="p">);</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="c1">// etc...</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p><code>Builder#has</code> method now maintains a query’s constraints (<a href="https://github.com/laravel/framework/commit/7196279d1f6c5a9e067beb6f39fea5eaa50e7c19"><code>7196279</code></a>)</p></li>
<li><p>Scoped queries now return the value from the scope method for better chaining (<a href="https://github.com/laravel/framework/commit/23adaa4068ad91fd934b58b6f60cef06135a76e3"><code>23adaa4</code></a>)</p>
<ul>
<li>In case you’re confused how this is new functionality (I was), previously, the magic method that called your custom scope method ignored what you returned and instead returned the <code>Builder</code> instance (which to be honest is the 95%+ use case anyway), but it now returns what you actually return from your scope method (so if you weren’t already, make sure you return the <code>Builder</code> instance!)</li>
</ul>
</li>
<li><p><code>has</code> queries got even better: new <code>whereHas()</code> and <code>orWhereHas()</code> that allow you to set specific constraints on the <code>has</code> relation (<a href="https://github.com/laravel/framework/commit/a634f45"><code>a634f45</code></a>):</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'><span class="c1">// get all users with posts pre-attached, but only users with</span>
</span><span class='line'><span class="c1">// at least one post that is more than a year old</span>
</span><span class='line'><span class="nx">User</span><span class="o">::</span><span class="na">with</span><span class="p">(</span><span class="s1">'posts'</span><span class="p">)</span><span class="o">-></span><span class="na">whereHas</span><span class="p">(</span><span class="s1">'posts'</span><span class="p">,</span> <span class="k">function</span> <span class="p">(</span><span class="nv">$query</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="nv">$query</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'created_at'</span><span class="p">,</span> <span class="s1">'<'</span><span class="p">,</span> <span class="nx">Carbon</span><span class="o">::</span><span class="na">now</span><span class="p">()</span><span class="o">-></span><span class="na">subYears</span><span class="p">(</span><span class="mi">1</span><span class="p">));</span>
</span><span class='line'><span class="p">})</span><span class="o">-></span><span class="na">get</span><span class="p">();</span>
</span></code></pre></td></tr></table></div></figure>
<p>I’m not sure right now if the <code>whereHas</code> affects the <code>with</code> (i.e. what actually gets returned pre-attached) or just the mechanism for filtering the original model by the relationship. My guess is the latter.</p>
<ul>
<li><p>New session configuration option <code>secure</code> (boolean) that will affect whether the session cookie gets sent via HTTPS only or not (<a href="https://github.com/laravel/framework/commit/37fa9a1c599069ea475e75cd540b9239f76ecc71"><code>37fa9a1</code></a> and [<code>laravel/laravel@f387853</code>](<a href="https://github.com/laravel/laravel/commit/">https://github.com/laravel/laravel/commit/</a></p></li>
<li><p>New short variable defaults in Eloquent (<a href="https://github.com/laravel/framework/commit/10f5bfae60a799b1f7862cb923e7cf2ecd086816"><code>10f5bfa</code></a>)</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="c"><!-- this --></span>
</span><span class='line'><span class="nt"><div></span>Hello, {{ isset($username) ? $username : 'anonymous' }}.<span class="nt"></div></span>
</span><span class='line'><span class="c"><!-- can now be done like this --></span>
</span><span class='line'><span class="nt"><div></span>Hello, {{ $username or 'anonymous' }}.<span class="nt"></div></span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p>Cache entries can now be tagged. New functionality includes using <code>Cache::tags</code> to get a list of the tags used in the cache, and items can be flushed by tag (<a href="https://github.com/laravel/framework/commit/70108fe4f456f343325234063aa77b9012ede7dd"><code>70108fe</code></a>)</p></li>
<li><p>Laravel now sends <code>X-frame-Options: SAMEORIGIN</code> by default in the HTTP headers (<a href="https://github.com/laravel/framework/commit/15513cc96790e33b7a136db381b06805863d3009"><code>15513cc</code></a>)</p></li>
<li><p><code>belongsToMany</code> relations now have a firstOrFail method (<a href="https://github.com/laravel/framework/commit/b162579b3911f59f5ca175d2d90d0a221cf6b109"><code>b162579</code></a>)</p></li>
<li><p>Schema builder now has <code>nullableTimestamps</code> method that creates timestamps as normal but makes them nullable fields (<a href="https://github.com/laravel/framework/commit/a44fbab722c276fca0b09d7a22e446b7894bee93"><code>a44fbab</code></a>)</p></li>
<li><p>Joins can now have complex conditions if <code>joinWhere</code> or <code>leftJoinWhere</code> are used (<a href="https://github.com/laravel/framework/commit/a644ea01fc3110b29a8f3a9ac96e039b3478953c"><code>a644ea0</code></a>)</p></li>
<li><p>New <code>required_without_all</code> validation rule that works like <code>required_without</code> but checks that at least one of the specified fields is present rather than all fields (<a href="https://github.com/laravel/framework/commit/93c1045fdea4d115d4a9dbc7ae64793bc7063d52"><code>93c1045</code></a>)</p></li>
<li><p>Original method that was attempted is passed to <code>Controller#missingMethod</code> now as the first parameter, with the additional parameters as an array as the second parameter (<a href="https://github.com/laravel/framework/commit/de871fe7db2798071e8ca877d04ba7e6629f9f18"><code>de871fe</code></a>)</p></li>
<li><p>New Blade <code>@append</code> method (<a href="https://github.com/laravel/framework/commit/f0ae98bfd0b07be739eaf9b9bf3505e916d25ca7"><code>f0ae98b</code></a>):</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'>@section('content')
</span><span class='line'>Some content for the content section
</span><span class='line'>@append
</span><span class='line'>
</span><span class='line'>...
</span><span class='line'>
</span><span class='line'>@section('content')
</span><span class='line'>Some more content for the content section
</span><span class='line'>@append
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p>New query builder <code>rememberForever</code> method (<a href="https://github.com/laravel/framework/commit/c6815845956e1cbd7039cefe67157ff0b3e8c557"><code>c681584</code></a>)</p></li>
<li><p>New Eloquent model <code>booting</code> and <code>booted</code> methods (<a href="https://github.com/laravel/framework/commit/2dfb3831d62f4689b9e234a83af46551df273609"><code>2dfb383</code></a>)</p></li>
<li><p><code>View#withErrors</code> now accepts an optional parameter that is a object that implements <code>MessageProviderInterface</code> (i.e. can be asked for a <code>MessageBag</code>)(<a href="https://github.com/laravel/framework/commit/3c5ca1a85dce7fc915c19b3cd197ad03433375b6"><code>3c5ca1a</code></a>)</p>
<ul>
<li>Use case here is for validators: <code>View::make('some.view')->withErrors($validator);</code></li>
</ul>
</li>
<li><p>A big change to password resetting/reminder stuff (<a href="https://github.com/laravel/framework/commit/f86d5ea61f6adc2004b8ed259a62cc8008d08fd0"><code>f86d5ea</code></a>)</p>
<ul>
<li><a href="https://github.com/laravel/docs/blob/master/security.md">Related documentation (may not yet be complete)</a></li>
</ul>
</li>
<li><p><code>Collection#splice</code> now returns the extracted elements (if any) as a new <code>Collection</code> (<a href="https://github.com/laravel/framework/commit/32f107dae8c052cc012c272e4d2b2f278b86aade"><code>32f107d</code></a>)</p></li>
<li><p>Commas are now allowed in route wildcards (<a href="https://github.com/laravel/framework/commit/fdd378bb072d6993be9798aa1772c394e65e5048"><code>fdd378b</code></a>)</p></li>
<li><p>Using host detection in <code>bootstrap/start.php</code> you should now just use the machine name rather than HTTP_HOST, this change is good because it bridges artisan and HTTP environment detection (<a href="https://github.com/laravel/laravel/commit/a297fe838946f1412e61647797df78eb5b24b267"><code>laravel/laravel@a297fe8</code></a>)</p></li>
<li><p>On a <code>BelongsToMany</code> relationship, you can now use <code>wherePivot</code> and <code>orWherePivot</code> to add constraints to the pivot table conveniently (<a href="https://github.com/laravel/framework/commit/5d485777847b5641101af68660b925e2cab30ec3"><code>5d48577</code></a>)</p></li>
<li><p>Database layer can now have separate connections for reading and writing. I’m not entirely sure why this was added but maybe it’s useful to some (<a href="https://github.com/laravel/framework/commit/a3b0e87ae50b22a517c6daea85e824ae2f0e27c0"><code>a3b0e87</code></a>). As I understand it from the tests, you can just override any settings from the connection’s config array in the <code>read</code> or <code>write</code> keys:</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// app/config/database.php</span>
</span><span class='line'>
</span><span class='line'><span class="k">return</span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'> <span class="c1">// ...</span>
</span><span class='line'>
</span><span class='line'> <span class="s1">'connections'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'> <span class="s1">'mysql'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'>
</span><span class='line'> <span class="c1">// default settings for read/write for this connection</span>
</span><span class='line'> <span class="s1">'driver'</span> <span class="o">=></span> <span class="s1">'mysql'</span><span class="p">,</span>
</span><span class='line'> <span class="s1">'host'</span> <span class="o">=></span> <span class="s1">'127.0.0.1'</span><span class="p">,</span>
</span><span class='line'> <span class="s1">'database'</span> <span class="o">=></span> <span class="s1">'laravel'</span><span class="p">,</span>
</span><span class='line'> <span class="s1">'username'</span> <span class="o">=></span> <span class="s1">'user'</span><span class="p">,</span>
</span><span class='line'> <span class="s1">'password'</span> <span class="o">=></span> <span class="s1">'pass'</span><span class="p">,</span>
</span><span class='line'> <span class="s1">'charset'</span> <span class="o">=></span> <span class="s1">'utf8'</span><span class="p">,</span>
</span><span class='line'> <span class="s1">'collation'</span> <span class="o">=></span> <span class="s1">'utf8_unicode_ci'</span><span class="p">,</span>
</span><span class='line'> <span class="s1">'prefix'</span> <span class="o">=></span> <span class="s1">''</span><span class="p">,</span>
</span><span class='line'>
</span><span class='line'> <span class="c1">// read-specific overrides</span>
</span><span class='line'> <span class="s1">'read'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span>
</span><span class='line'> <span class="s1">'database'</span> <span class="o">=></span> <span class="s1">'laravel_read'</span><span class="p">,</span>
</span><span class='line'> <span class="p">),</span>
</span><span class='line'> <span class="p">),</span>
</span><span class='line'> <span class="p">),</span>
</span><span class='line'><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p>Lots of work on queues (in particular releasing jobs back to the queue for Iron.io queues, as well as logging failed queue jobs into a database connection) (multiple commits).</p></li>
<li><p><code>Collection</code> class now has <code>merge</code>, <code>diff</code> and <code>intersect</code> methods to work with multiple collections (<a href="https://github.com/laravel/framework/commit/2f5402411717232f9cb9bacfd0bc3aee4f353716"><code>2f54024</code></a>).</p></li>
<li><p><code>Paginator</code> has a new method <code>fragment</code> which can be used to set the fragment to be appended to the URIs generated by the paginator (if passed a string) or get the current fragment (if the argument is omitted or null) (<a href="https://github.com/laravel/framework/commit/ea9a92483479155b393462f2a2bcbb4a2c246fff"><code>ea9a924</code></a>):</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="nv">$paginator</span><span class="o">-></span><span class="na">fragment</span><span class="p">(</span><span class="s1">'my-frag'</span><span class="p">);</span> <span class="c1">// sets the fragment to be 'my-frag'</span>
</span><span class='line'><span class="k">echo</span> <span class="nv">$paginator</span><span class="o">-></span><span class="na">fragment</span><span class="p">();</span> <span class="c1">// echoes the current fragment (i.e. 'my-frag')</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Eloquent’s <code>Collection#find</code> can now accept a model as the ‘key’ and it’ll search in the collection for a model which has the same key as the passed model (<a href="https://github.com/laravel/framework/commit/362db89e635eda87faf8c0db0935e3fe0d74f5bf"><code>362db89</code></a>):</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// get all enabled pages</span>
</span><span class='line'><span class="nv">$pages</span> <span class="o">=</span> <span class="nx">Page</span><span class="o">::</span><span class="na">whereEnabled</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">-></span><span class="na">get</span><span class="p">();</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// get page with id of 1</span>
</span><span class='line'><span class="nv">$page</span> <span class="o">=</span> <span class="nx">Page</span><span class="o">::</span><span class="na">find</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// before:</span>
</span><span class='line'><span class="k">if</span> <span class="p">(</span><span class="nv">$pages</span><span class="o">-></span><span class="na">contains</span><span class="p">(</span><span class="nv">$page</span><span class="o">-></span><span class="na">getKey</span><span class="p">()))</span> <span class="p">{</span>
</span><span class='line'> <span class="c1">// do something</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// now:</span>
</span><span class='line'><span class="k">if</span> <span class="p">(</span><span class="nv">$pages</span><span class="o">-></span><span class="na">contains</span><span class="p">(</span><span class="nv">$page</span><span class="p">))</span> <span class="p">{</span>
</span><span class='line'> <span class="c1">// do something</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Locking added to <code>QueryBuilder</code> (<a href="https://github.com/laravel/framework/commit/a33143257d9bed8c81065ebc6513e3cca7d3f124"><code>a331432</code></a>):
<ul>
<li><code>$builder->lockForUpdate()</code> – same as calling <code>$builder->lock(true)</code></li>
<li><code>$builder->sharedLock()</code> – same as calling <code>$builder->lock(false)</code></li>
<li><code>$builder->lock([string|boolean])</code>
<ul>
<li>If <code>true</code>, signifies the row should be locked for update</li>
<li>If <code>false</code>, signifies that the row should be locked for share</li>
<li>If a string, the string will be used as the text to go in the ‘lock’ part of the query</li>
</ul>
</li>
<li>It would appear that even if you don’t do anything to do with locks, you will now always get the shared lock due to the way the lock variable is handled, but maybe I’m wrong there, or maybe that’s implicit in RDBMSes anyway so it doesn’t harm anyone</li>
</ul>
</li>
</ul>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-11-01T13:20:00+00:00" data-updated="true" itemprop="datePublished">1<span>st</span> November 2013</time></div>
<div class="tags">
<a class='category' href='/blog/categories/code/'>Code</a>, <a class='category' href='/blog/categories/laravel/'>Laravel</a>, <a class='category' href='/blog/categories/laravel-digest/'>Laravel Digest</a>
</div>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/11/laravel-digest-october-2013/" itemprop="url">Laravel Digest (October 2013)</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>Welcome to the second instalment of Laravel Digest, the series where I give a regular rundown of important changes, fixes and additions to Laravel’s master branch. Below are the changes up to the end of October 2013:</p>
<ul>
<li>Blade braces can now be escaped using <code>@</code> which is useful for people using clientside templating languages that also use the braces (<a href="https://github.com/laravel/framework/commit/cb93bf3df8d25c04939462f81b75ddb9e4e6faa0"><code>cb93bf3</code></a>):</li>
</ul>
<p>The following code will output <code>hello</code></p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'>{{ 'hello' }}
</span></code></pre></td></tr></table></div></figure>
<p>The following code will output <code>{{ $variable }}</code></p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'>@{{ $variable }}
</span></code></pre></td></tr></table></div></figure>
<p>Use case, using handlebars.js:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt"><div</span> <span class="na">class=</span><span class="s">"name"</span><span class="nt">></span>@{{ user.name }}<span class="nt"></div></span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p>Queued cookies – because cookies can only be attached to a request, using <code>Cookie::set()</code> before the request was instantiated previous lost the cookie (or simply wasn’t allowed). Now <code>Cookie::queue()</code> can be used to queue cookies for eventual sending with the request.</p></li>
<li><p><code>Route::controller</code> is back and appears slightly cleverer than before in that it first seeks out all callable methods on the given controller and adds each route individually, then sets up a ‘default’ route for anything it can’t detect (<a href="https://github.com/laravel/framework/commit/98c14a9f90ada608418490e4cfacd51f4ebda384"><code>98c14a9</code></a>)</p>
<ul>
<li><code>Route::controllers</code> can also be used to hook multiple controllers up in one go by passing an associative array of uri to controller FQCN</li>
</ul>
</li>
<li><p><code>App::env()</code> can now be used to check the environment against a list provided (array or multiple arguments) (<a href="https://github.com/laravel/framework/commit/66e5a0b32f61b1ec0e14aa4bc4219d15c2a247c7"><code>66e5a0b</code></a>)</p></li>
<li><p>Remote tail command (<code>artisan tail</code>) allows tailing of a remote log file (assuming the remote connection is set up correctly in the config and the remote project uses a single log file) (<a href="https://github.com/laravel/framework/commit/25b1cac27080641b289c2ad791b734efff92bcef"><code>25b1cac</code></a>)</p>
<ul>
<li>As a consequence of this work, the logging system was simplified down to a single log file by default (no daily rotation and no SAPI name, this looks like it may generate rather large log files to me, I’d have preferred to keep daily rotation) (<a href="https://github.com/laravel/laravel/commit/088f4b69b6b9846dd54b55688f11e44b9bc73483"><code>laravel/laravel@088f4b6</code></a>)</li>
<li>Also as a consequence, the live debugging through sockets was removed. Now the <code>tail</code> command will tail a remote log file if there’s a remote connection specified, or tail the local log file if there’s no remote connection specified (<a href="https://github.com/laravel/framework/commit/f62d1a727155073357babee95a8f679003a8b93c"><code>f62d1a7</code></a>/<a href="https://github.com/laravel/framework/commit/763a02652ba23a9b61f59b47c05ab146bbe76136"><code>763a0265</code></a>)</li>
</ul>
</li>
<li><p>New <code>Router::input()</code> method that allows you to get the value of a named route parameter (<a href="https://github.com/laravel/framework/commit/28e36bbc0296e3b4cdf5ae18c5a972923c05b4de"><code>28e36bb</code></a>)</p></li>
<li><p>Controller filters can now be added as controller functions using the <code>@</code> syntax as a shorthand (see <a href="https://github.com/laravel/framework/issues/2432">issue 2432</a>) (<a href="https://github.com/laravel/framework/commit/d0e0c632e2b3ff15746e48ec7bd57c5cc51d0ae0"><code>d0e0c63</code></a>):</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">UserController</span> <span class="k">extends</span> <span class="nx">Contoller</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'> <span class="k">public</span> <span class="k">function</span> <span class="nf">__construct</span><span class="p">()</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="c1">// before:</span>
</span><span class='line'> <span class="nv">$this</span><span class="o">-></span><span class="na">beforeFilter</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="nv">$route</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="nv">$this</span><span class="o">-></span><span class="na">hasPermission</span><span class="p">(</span><span class="nv">$route</span><span class="p">);</span>
</span><span class='line'> <span class="p">},</span> <span class="p">[</span><span class="s1">'only'</span> <span class="o">=></span> <span class="s1">'edit'</span><span class="p">]);</span>
</span><span class='line'>
</span><span class='line'> <span class="c1">// after, shorthand</span>
</span><span class='line'> <span class="nv">$this</span><span class="o">-></span><span class="na">beforeFilter</span><span class="p">(</span><span class="s1">'@hasPermission'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'only'</span> <span class="o">=></span> <span class="s1">'edit'</span><span class="p">]);</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">public</span> <span class="k">function</span> <span class="nf">hasPermission</span><span class="p">(</span><span class="nv">$route</span><span class="p">)</span>
</span><span class='line'> <span class="p">{</span>
</span><span class='line'> <span class="nv">$id</span> <span class="o">=</span> <span class="nv">$route</span><span class="o">-></span><span class="na">getParameter</span><span class="p">(</span><span class="s1">'id'</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'> <span class="k">if</span> <span class="p">(</span><span class="o">!</span> <span class="nx">Auth</span><span class="o">::</span><span class="na">user</span><span class="p">()</span><span class="o">-></span><span class="na">ownsPost</span><span class="p">(</span><span class="nv">$id</span><span class="p">))</span> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="nx">Response</span><span class="o">::</span><span class="na">make</span><span class="p">(</span><span class="s1">'You are not authorised to edit this post'</span><span class="p">,</span> <span class="mi">401</span><span class="p">);</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p>Can now pass DateTime and Carbon instances to Cache method that accept a duration (in this case, the time difference between now and the time passed is calculated in minutes) (<a href="https://github.com/laravel/framework/commit/977f803030b84ce28f034bcf925f93bfb029a0d4"><code>977f803</code></a>)</p></li>
<li><p>Now uses <a href="http://stackphp.com/">Stack</a> for middleware (multiple commits). Repercussions:</p>
<ul>
<li><code>close</code> application hook is now deprecated in favour of using a stack middleware (<a href="https://github.com/laravel/framework/commit/18e1aecb69897b9533968d4c9f291f3a522ef98f"><code>18e1aec</code></a>)</li>
<li>Presumably more…</li>
</ul>
</li>
<li><p>Should now use Input::cookie for cookies, not Cookie::get (<a href="https://github.com/laravel/framework/commit/e0fe79e398003e54d54f2626e1283e97209b7f50"><code>e0fe79e</code></a> removed <code>Cookie::get()</code> and <a href="https://github.com/laravel/framework/commit/58ec2fe05f092bdd09f2e05d8a86633b97417cef"><code>58ec2fe</code></a> for temporary deprecation code in the facade)</p></li>
<li><p>If using MySQL, <code>UPDATE</code> queries can now have <code>orderBy</code> and <code>limit</code> specified (<a href="https://github.com/laravel/framework/commit/d9d61e13fc2f01efc00c9b87ff6f1e91bab1e9b8"><code>d9d61e1</code></a>)</p></li>
<li><p>As with overriding packages’ config and views, translations can now be overridden using a similar convention (<a href="https://github.com/laravel/framework/commit/5483042e8762d4f8ffc356579ddaae4f7dc3cbc9"><code>5483042</code></a>)</p>
<ul>
<li><p>It should be noted that the convention is not the same: it is not <code>app/lang/packages/vendor/package/</code> but uses the namespace (i.e. package name) <em>only</em>, like when referencing views/config (i.e. <code>View::make('namespace:path.view')</code> and <code>Config:get('namespace:config.key')</code>)</p></li>
<li><p>Files for a package <code>vendor/package</code> in locale <code>en</code> should go in <code>app/lang/packages/en/package/</code> — see how it’s just <code>package</code> not <code>vendor/package</code> like it would be for config and views</p></li>
<li><p>So to reiterate, for a package called <code>vendor/package</code>:</p>
<ul>
<li>Views: <code>View::make('package::some/view')</code> ⟶ <code>app/views/packages/vendor/package/some/view{.blade}.php</code></li>
<li>Config: <code>Config::get('package::some.key')</code> ⟶ <code>app/config/packages/vendor/package/some.php</code>, then key <code>key</code></li>
<li>Translations: <code>Lang::get('package::some.key')</code> ⟶ <code>app/lang/packages/en/package/some.php</code>, then key <code>key</code></li>
</ul>
</li>
</ul>
</li>
<li><p>You can now use <code>Auth::viaRemember()</code> to determine whether the logged-in user was authorised through the ‘remember me’ cookie or not (<a href="https://github.com/laravel/framework/commit/2184ad4c8fe5f05b89ae1d5c6f87012cca150101"><code>2184ad4</code></a>)</p></li>
<li><p>New <code>bindShared</code> method on the IoC container which should now be used in place of the old share syntax (<a href="https://github.com/laravel/framework/commit/07233b32eb190dffde427b3aee1e5e4f855abd00"><code>07233b3</code></a>):</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="c1">// this</span>
</span><span class='line'><span class="nv">$this</span><span class="o">-></span><span class="na">app</span><span class="p">[</span><span class="s1">'my.key'</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">app</span><span class="o">-></span><span class="na">share</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="nv">$app</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="k">new</span> <span class="nx">MyClass</span><span class="p">();</span>
</span><span class='line'><span class="p">});</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// becomes this</span>
</span><span class='line'><span class="nv">$this</span><span class="o">-></span><span class="na">app</span><span class="o">-></span><span class="na">bindShared</span><span class="p">(</span><span class="s1">'my.key'</span><span class="p">,</span> <span class="k">function</span> <span class="p">(</span><span class="nv">$app</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="k">new</span> <span class="nx">MyClass</span><span class="p">();</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p><code>ServiceProvider</code> no longer uses very weird logic to guess a package’s namespace. This probably won’t affect many people but I’m pointing it out as it has affected me and it’s good to know for future reference (<a href="https://github.com/laravel/framework/commit/6089525e1293407085c07588f2eb8b2cd8644b01"><code>6089525</code></a>)</p></li>
<li><p>You can now pass a view to <code>Paginator::links([$view])</code> in order to override the default view for that call (<a href="https://github.com/laravel/framework/commit/9d1150c8851d22cb1a14faa35304b3dc7f17c94b"><code>9d1150c</code></a>)</p></li>
<li><p>New <code>hasManyThrough</code> relation type (<a href="https://github.com/laravel/framework/commit/0925d868b900372a39c0f9985308004d24bad46d"><code>0925d86</code></a>)</p>
<ul>
<li>There’s no real documentation on this yet and the tests are a little cryptic, so I’ll talk more about this in the next update.</li>
</ul>
</li>
<li><p><code>Validator::make</code> can now take a fourth parameter that specified the custom parameters for the validator. Presumably to be used by custom validators. (<a href="https://github.com/laravel/framework/commit/93977e49559ec82e8a82f19bbdfcf4f27cfb4ac0"><code>93977e4</code></a>)</p></li>
<li><p>IoC container old <code>resolving</code> method is now renamed to <code>resolvingAny</code> and now there’s a new <code>resolving</code> method in its place that accepts an abstract object type to only be fired when that abstract type is being resolved (<a href="https://github.com/laravel/framework/commit/aa6df0aa52f588c588c2f0c0646039ad35efe19b"><code>aa6df0a</code></a>)</p></li>
<li><p>Any alaises bound to a given IoC key will now be removed when rebinding the key (<a href="https://github.com/laravel/framework/commit/8f240f83785e1aebd0d5abf848d8425786a9ba86"><code>8f240f8</code></a>)</p></li>
<li><p>Queue workers will no no longer run if the application is in maintenance mode (<a href="https://github.com/laravel/framework/commit/a8cdb683a097e04281ada784d9073c8a83f72bf1"><code>a8cdb68</code></a>)</p></li>
</ul>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-10-25T20:22:00+01:00" data-updated="true" itemprop="datePublished">25<span>th</span> October 2013</time></div>
<div class="tags">
<a class='category' href='/blog/categories/code/'>Code</a>, <a class='category' href='/blog/categories/composer/'>Composer</a>, <a class='category' href='/blog/categories/php/'>PHP</a>
</div>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/10/adding-project-dependencies-with-composer-require/" itemprop="url">Adding Project Dependencies With Composer Require</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>Composer’s been around for some time now, and gained a lot of popularity since its use in Laravel 4. I noticed back in the first half of 2013 that a lot of blogs and tutorials were teaching installation of packages (or, more correctly, addition of project dependencies) by editing your <code>composer.json</code> file’s <code>require</code> array and then doing a <code>composer update</code> on the command line. I thought back then that maybe because composer was new to these people (in general these were related to Laravel 4 which was in development at the time) they hadn’t yet discovered the easier, and technically less error-prone, way to do this that very few people seemed to be using and advising: <code>composer require</code></p>
<p>Well it seems that most people still haven’t discovered the command, so I figured I would write about it. Instead of (possibly erroneously) manually editing your <code>composer.json</code> file to add a new package to your project’s dependencies and then calling <code>composer update</code>, you can use <code>composer require</code> to do the job for you. You’re having to use the command line anyway, so why not skip the manual editing of <code>composer.json</code> part?</p>
<p>The syntax is really simple:</p>
<pre><code>composer require vendor/package version
</code></pre>
<p>It’s as easy as that. And you can even require a dev dependency with the <code>--dev</code> option:</p>
<pre><code>composer require mockery/mockery 0.8.0 --dev
</code></pre>
<p>In fact, the command can be used to add multiple packages to your project’s dependencies by simply separating them with a space. In this case, it’s probably best to use the alternative version constraint syntax which is <code>vendor/package:version</code> or <code>vendor/package=version</code>:</p>
<pre><code>composer require --dev mockery/mockery:0.8.0 phpunit/phpunit:~3.7.4
</code></pre>
<p>Also notice how the <code>--dev</code> can go either before or after the packages — use what works best for you.</p>
<p>Another good thing about it is that if anything goes wrong during installation of the packages or their dependencies then Composer will leave your composer.json file unchanged.</p>
<hr />
<p>There is one caveat to this: if you wish to use the asterisk to denote any patch or minor version is okay, then it’s best to put the argument in question in quotes so that your shell doesn’t try (and probably fail) to interpret it as a glob on the filesystem. In my case (using <a href="http://fishshell.com/">fish</a>) the following happens:</p>
<pre><code>> composer require mockery/mockery 0.8.* --dev
fish: No matches for wildcard '0.8.*'.
composer require mockery/mockery 0.8.* --dev
^
</code></pre>
<p>However, with the argument quoted it’s all good:</p>
<pre><code>composer require "mockery/mockery 0.8.*" --dev
</code></pre>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-10-04T10:55:00+01:00" data-updated="true" itemprop="datePublished">4<span>th</span> October 2013</time></div>
<div class="tags">
<a class='category' href='/blog/categories/code/'>Code</a>, <a class='category' href='/blog/categories/laravel/'>Laravel</a>, <a class='category' href='/blog/categories/laravel-digest/'>Laravel Digest</a>
</div>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/10/laravel-digest-september-2013/" itemprop="url">Laravel Digest (September 2013)</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>Introducing Laravel digest, where I let you know what’s changed in the most recent commits to Laravel. I like to think of it as me reading the commitlog so you don’t have to. The general idea is that I’ll list out any notable changes on the master branch (although really I’m looking at both master and 4.0) since the previous update. I pretty much decide what’s classed as notable, but usually it’ll be stuff that actually affects the way developers work, so small bugfixes won’t be in, but new features or uses of existing components are included.</p>
<p>As this is the first installment of Laravel digest there’s no “since last time” so I’m arbitrarily deciding its since about mid-September. A fortnight seems like a good period of time between updates (and maybe longer where Taylor has less time to spend on the framework).</p>
<p>So, without further ado:</p>
<p>Notable recent changes (since approx. 15 September 2013) on master specifically (but most apply to 4.0 too):</p>
<ul>
<li><p><code>artisan tinker</code> is now a full REPL using <a href="https://github.com/d11wtq/boris">Boris</a> (<a href="https://github.com/laravel/framework/commit/5e8d2c0e38b9630cf881336cbfde6c64657e4d30"><code>5e8d2c0</code></a>)</p>
<ul>
<li>It does, however, require <code>ext_readline</code> and <code>ext_posix</code> if you want to use it though (ouch!)</li>
</ul>
</li>
<li><p>Views can have data added eloquently (<a href="https://github.com/laravel/framework/commit/e7fd520a8b7d38b9aa68aee8fea880b725da46e9"><code>e7fd520</code></a>)</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// this</span>
</span><span class='line'><span class="k">return</span> <span class="nx">View</span><span class="o">::</span><span class="na">make</span><span class="p">(</span><span class="s1">'view.name'</span><span class="p">)</span><span class="o">-></span><span class="na">with</span><span class="p">([</span><span class="s1">'user'</span> <span class="o">=></span> <span class="nv">$user</span><span class="p">]);</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// or this</span>
</span><span class='line'><span class="k">return</span> <span class="nx">View</span><span class="o">::</span><span class="na">make</span><span class="p">(</span><span class="s1">'view.name'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'user'</span> <span class="o">=></span> <span class="nv">$user</span><span class="p">]);</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// becomes this</span>
</span><span class='line'><span class="k">return</span> <span class="nx">View</span><span class="o">::</span><span class="na">make</span><span class="p">(</span><span class="s1">'view.name'</span><span class="p">)</span><span class="o">-></span><span class="na">withUser</span><span class="p">(</span><span class="nv">$user</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p>View composers can have a priority attached so they run in a given order (<a href="https://github.com/laravel/framework/commit/fb4fe45a9c795e250d046e87f6c3c86a6d01f850"><code>fb4fe45</code></a>)</p></li>
<li><p>Developers can specify a protected instance <code>dates</code> array in their Eloquent models that returns an array of fields that should be treated like dates (<a href="https://github.com/laravel/framework/commit/f15b034dc744290a08e0abc776f06ed991426d4e"><code>f15b034</code></a>)</p></li>
<li><p>Query builder/Eloquent now has a chunk method that allows for working through large datasets without killing RAM usage (<a href="https://github.com/laravel/framework/commit/11d3e9850dc6139850d5e81c71067ae2d7a894d9"><code>11d3e98</code></a>):</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="nx">User</span><span class="o">::</span><span class="na">whereActive</span><span class="p">(</span><span class="s1">'1'</span><span class="p">)</span><span class="o">-></span><span class="na">chunk</span><span class="p">(</span>
</span><span class='line'> <span class="mi">100</span><span class="p">,</span> <span class="c1">// per chunk</span>
</span><span class='line'> <span class="k">function</span><span class="p">(</span><span class="nv">$results</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="c1">// do something with set of 100 results at a time</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><code>Route::group</code> config array now accepts a <code>namespace</code> string that will automatically prefix controller names with the namespace – they can even be nested (<a href="https://github.com/laravel/framework/commit/3d0400e55a81b79d3352670f2e24f7358eb95d10"><code>3d0400e</code></a>)</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// something a bit like this</span>
</span><span class='line'><span class="nx">Route</span><span class="o">::</span><span class="na">group</span><span class="p">(</span>
</span><span class='line'> <span class="p">[</span><span class="s1">'prefix'</span> <span class="o">=></span> <span class="s1">'admin'</span><span class="p">],</span>
</span><span class='line'> <span class="k">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">Route</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="s1">'some/url'</span><span class="p">,</span> <span class="s1">'MyApp\\Admin\\UserController@index'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">Route</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="s1">'some/other/url'</span><span class="p">,</span> <span class="s1">'MyApp\\Admin\\UserController@edit'</span><span class="p">);</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// can become the slightly cleaner</span>
</span><span class='line'><span class="nx">Route</span><span class="o">::</span><span class="na">group</span><span class="p">(</span>
</span><span class='line'> <span class="p">[</span><span class="s1">'prefix'</span> <span class="o">=></span> <span class="s1">'admin'</span><span class="p">,</span> <span class="s1">'namespace'</span> <span class="o">=></span> <span class="s1">'MyApp\\Admin'</span><span class="p">],</span>
</span><span class='line'> <span class="k">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">Route</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="s1">'users'</span><span class="p">,</span> <span class="s1">'UserController@index'</span><span class="p">);</span>
</span><span class='line'> <span class="nx">Route</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="s1">'user/edit'</span><span class="p">,</span> <span class="s1">'UserController@edit'</span><span class="p">);</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Query builder/Eloquent can now find multiple rows with <code>find()</code> by passing an array (<a href="https://github.com/laravel/framework/commit/911e08b1501c45b7b58a62007708bc9494e385b5"><code>911e08b</code></a>)</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// get users 1 and 5</span>
</span><span class='line'><span class="nv">$users</span> <span class="o">=</span> <span class="nx">User</span><span class="o">::</span><span class="na">find</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">]);</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p>Can get current environment using <code>artisan env</code> (useful for debugging weird database connection issues with artisan – not so useful for knowing what environment the web site is running as artisan and the running web instance will use different methods to determine the environment, so they could quite easily be different) (<a href="https://github.com/laravel/framework/commit/5c7ba12fda225a295ae96dbb7770f4859aa65330"><code>5c7ba12</code></a>)</p></li>
<li><p>Can now return an ArrayObject from a route action and it’ll be serialised as JSON (previously it was just just bare arrays and JsonableInterface objects) (<a href="https://github.com/laravel/framework/commit/bd4b0c6eb5633c8ebf6daf7ed2329550fb2761d5"><code>bd4b0c6</code></a>)</p></li>
<li><p>Packages’ views can now be published (like config and assets were) using <code>artisan view:publish</code> (<a href="https://github.com/laravel/framework/commit/44a27da7245b5da88fd97934d250b59813127053"><code>44a27da</code></a>)</p></li>
<li><p>Paginator can now be returned from a route action and it’ll be serialised to JSON (good for paginated responses in APIs) (<a href="https://github.com/laravel/framework/commit/5875b60d823b331ee838ebbe74fbc64a53c520a4"><code>5875b60</code></a>)</p></li>
<li><p>Eloquent query builder now has <code>firstOrNew</code> and <code>firstOrCreate</code> methods (<a href="https://github.com/laravel/framework/commit/fce86bc9b53cb693284ea1dc557b3034375fd1ca"><code>fce86bc</code></a>):</p>
<ul>
<li><code>firstOrNew</code> tries to use the passed array of attributes to find the model, and if it can’t find it it’ll create a new (unsaved) instance of the model</li>
<li><code>firstOrCreate</code> tries to use the passed array of attributes to find the model, and if it can’t find it it’ll create a new instance of the model and save it immediately</li>
<li><strong>Implementation note:</strong> this also uses a convenient new method <code>firstByAttributes</code> which is unfortunately protected in <code>Illuminate\Database\Eloquent\Model</code>. The method is nothing special, just cycles through the array adding <code>where</code>s to a query builder</li>
</ul>
</li>
<li><p>new <code>Redirect::away</code> method allows passing of any URL – the passed URL is not validated, works just like <code>Redirect::to</code> otherwise (<a href="https://github.com/laravel/framework/commit/8c47d1173a8f666d8be278219f63d3c51459379e"><code>8c47d11</code></a>)</p></li>
<li><p>Remote feature now allows setting the port (<a href="https://github.com/laravel/framework/commit/3f7c47cb243be3ba201bf75c6c0c38e7b96b43b3"><code>3f7c47c</code></a>)</p></li>
<li><p>Like the Eloquent view data from <code>e7fd520</code>, redirects can do the same (<a href="https://github.com/laravel/framework/commit/97bbfe6f09e7b0a5143d65568e886f7a1ace2f9c"><code>97bbfe6</code></a>):</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="o"><?</span><span class="nx">php</span>
</span><span class='line'>
</span><span class='line'><span class="nx">Redirect</span><span class="o">::</span><span class="na">route</span><span class="p">(</span><span class="s1">'login'</span><span class="p">)</span><span class="o">-></span><span class="na">withMessage</span><span class="p">(</span><span class="s1">'Please log in'</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Validator now has a <code>sometimes</code> method that allows to set conditional rules (<a href="https://github.com/laravel/framework/commit/ffa70d312c8e639ce36e2859d4977dba123a2af6"><code>ffa70d3</code></a>, <a href="http://laravel.com/docs/validation#conditionally-adding-rules">docs</a>):</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>