@laravelbackpack
Backpack for Laravel
1 day
#Laravel #PHP Do you use compact() when passing data to views....? Is it an elegant shorthand or readability killer? Drop your thoughts in the comments!๐Ÿ‘‡
21
8
100

Replies

@laravelbackpack
Backpack for Laravel
2 hours
Enjoyed this tweet? Follow us - you will probably enjoy our other posts: https://t.co/q0R9wa0bh6
0
0
0
@blister
Eric Harrison
23 hours
@laravelbackpack What does it do? Grab the variable by named reference from $_GLOBALS or something? I have never seen this before.
0
0
0
@venelinkochev
Venelin K.
1 day
@laravelbackpack I don't use it ... it makes debugging harder when you need to track down where variables come from
0
0
12
@LukasAugustas
Irwin M. Fletcher
1 hour
X is throttling my posts.its also showing me a bunch of 1diot leftoid posts even though I muted them. My posts get 15 views with 3k plus followers? Might as well be 2017 again...hey @elonmusk ...WHAT THE FCK?!!!
0
0
6
@keantech
KEANTECH
21 hours
@laravelbackpack I always use this : $data = [] ; $data['user'] = $user; return view('dashboard', $data); Then in blade {{$user->id}} etc
0
0
1
@imvismay_
Vismay
2 hours
@laravelbackpack I never use compact
0
0
0
@terdelyi
Tamas Erdelyi
10 hours
@laravelbackpack I used it in the early days (Laravel 4โ€“5). It's great for smaller projects with fewer variables to push to the view, but after 6โ€“10 attributes it becomes too much work to maintain. Pass an array where you can manage the name of your variables directly or a ViewModel/DTO.
0
0
3
@joshmanders
Josh Manders
18 hours
@laravelbackpack I like it. It's the PHP version of object shorthand (`view('dashboard', { user, posts })`) in JavaScript.
0
0
2
@Bmaz762183
Varius๐ŸŒน
1 day
0
0
0
@mufratnir
Mufrat nir
16 hours
@laravelbackpack I use compact() most of the time โ€” itโ€™s clean and quick. But when sharing code with juniors or teams, explicit arrays are definitely more readable ๐Ÿ‘€
0
0
0
@G3z
Giacomo Trezzi
1 day
@laravelbackpack While I like itโ€™s readability, I donโ€™t do it because vscode doesnโ€™t understand that itโ€™s the $user variable, I would have loved to do compact($user, $posts)
1
0
2
@waunakeesoccer1
Andrew "buy the dip" Brown
1 day
@laravelbackpack it was fine back in the day, but we now have better solutions that allow for better diffs and help avoid unnecessary temporary variables.
0
0
0
@NabeelMolham
Nabeel ุงู„ุจุฑู…ุฌูŠ!
18 hours
@laravelbackpack The only performance cost for this function that it checks of variable exists or not, skips any undefined variable without stopping the script. It shows a warning but still builds the array, which leads to additional cpu cycles unnecessarily. Just be aware
0
0
0
@massivebrains00
Segun Olaiya โœจ
1 day
@laravelbackpack compact is the worst. It should not even exist
2
0
4
@som_funcky
som_funcky
23 hours
@laravelbackpack I almost never use compact ๐Ÿ˜Š
0
0
0
@japaneseremedy
symbols
23 hours
@laravelbackpack been using laravel since v4. not a big fan. pass in a bag
0
0
0
@ayzerobug
Ayzerobug | Building MVPs and SAAS
1 day
@laravelbackpack I use do use compact; but not when I have more than 2 array keys
0
0
1
@FindVoters_
M.K.Sharma
22 days
The pharmaceutical fallacy lies with the idea that everyone claims price controls will eliminate profitability and decrease the profit motive that fuels the growth of medicines. This is only partially true because a profit motive is required, but how much? This contributes to the
3
4
27
@ai_naresh
Naresh Kumar
1 day
@laravelbackpack i use this
0
0
1
@0x_brun0
Bruno
24 hours
@laravelbackpack Compact is so obscure ๐Ÿ˜…
0
0
0
@ankit_builds
Ankit Chaudhary
24 hours
@laravelbackpack Back in 2015, I worked for @opencart and there we used to define the variable as an array and pass it directly to the view. So sometimes or often, I do the same in Laravel ๐Ÿ‘‡
0
0
3
@abiruzzaman_m
Md Abiruzzaman Molla
7 hours
@laravelbackpack passing the $data array :P
0
0
0
@ren_3107
ใƒฌใƒณใ ใ‚ˆ
1 day
@laravelbackpack It does not only kill readability it makes your views break upon renaming any compacted variable. Honestly shouldn't be in the framework anymore.
0
0
2