This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0: { | |
file_name: "wallpaper", | |
validated: true, | |
extension: "jpg" | |
}, | |
1: { | |
file_name: "spring", | |
validated: true, | |
extension: "png" | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return collect($photos) | |
->where('validated', true) | |
->tap(function ($validated) { | |
return $validated->where('extension', 'jpg')->pluck('file_name'); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return collect($photos) | |
->where('validated', true) | |
->pipe(function ($validated) { | |
return $validated->where('extension', 'jpg')->pluck('file_name'); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return collect($photos) | |
->where('validated', true) | |
->tap(function ($validated) { | |
return var_dump($validated->pluck('file_name')); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$photos = [ | |
['file_name' => 'wallpaper', 'validated' => true, 'extension' => 'jpg'], | |
['file_name' => 'spring', 'validated' => true, 'extension' => 'png'], | |
['file_name' => 'flowers', 'validated' => false, 'extension' => 'jpg'], | |
['file_name' => 'mac', 'validated' => true, 'extension' => 'png'], | |
['file_name' => 'books', 'validated' => false, 'extension' => 'jpg'], | |
['file_name' => 'mobiles', 'validated' => false, 'extension' => 'jpg'], | |
['file_name' => 'glass', 'validated' => false, 'extension' => 'png'], | |
['file_name' => 'fruit', 'validated' => true, 'extension' => 'jpg'], | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$photo = App\Photo::find(1); | |
return tap($photo)->update([ | |
'validated' => 'true', | |
]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tap($value, $callback = null) | |
{ | |
if (is_null($callback)) { | |
return new HigherOrderTapProxy($value); | |
} | |
$callback($value); | |
return $value; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return tap($photo, function($photo) { | |
$photo->validated = true; | |
$photo->save(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tap($value, $callback) | |
{ | |
$callback($value); | |
return $value; | |
} |
NewerOlder