投稿時間:2022-07-13 10:33:32 RSSフィード2022-07-13 10:00 分まとめ(38件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… Microsoft、2022年7月のセキュリティ更新プログラムをリリース https://taisy0.com/2022/07/13/159070.html microsoft 2022-07-13 00:54:40
IT 気になる、記になる… iTunes Storeの「今週の映画」、今週は「アメリカン・ユートピア」(レンタル102円) https://taisy0.com/2022/07/13/159066.html apple 2022-07-13 00:48:50
IT 気になる、記になる… 【Amazon プライムデー】「Music Unlimited」や「Kindle Unlimited」などの各種キャンペーンも本日限り https://taisy0.com/2022/07/13/159063.html amazon 2022-07-13 00:04:50
ROBOT ロボスタ 世界とつながる窓「Atmoph Window 2」海外撮影を本格再始動 ハワイ・オアフ島の風景6本をリリース https://robotstart.info/2022/07/13/hawaii-atmoph-window-2.html 2022-07-13 00:00:13
IT ITmedia 総合記事一覧 [ITmedia News] Twitter、イーロン・マスク氏を提訴 買収契約の「責任を追わせるための訴訟」 https://www.itmedia.co.jp/news/articles/2207/13/news074.html itmedianewstwitter 2022-07-13 09:30:00
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] 栃木・奥日光にグランピング施設、2022年9月にオープン 中禅寺湖や男体山を一望 https://www.itmedia.co.jp/business/articles/2207/13/news073.html itmedia 2022-07-13 09:25:00
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] 全体の3割以上! 土屋鞄製造所、ジェンダーレスのランドセルが好調 https://www.itmedia.co.jp/business/articles/2207/13/news069.html itmedia 2022-07-13 09:16:00
デザイン コリス CSSでこんなことができるの知ってた? 要素・コンテナのサイズに関係なく、ボーダーや背景をはみ出して配置するテクニック https://coliss.com/articles/build-websites/operation/css/css-only-extended-border-and-background.html 続きを読む 2022-07-13 00:36:04
GCP gcpタグが付けられた新着投稿 - Qiita AizuHack LINEBot勉強会 Vol.4 https://qiita.com/shinbunbun_/items/43e2c486ac8839a6d32e volaizuh 2022-07-13 09:47:38
技術ブログ Developers.IO Azure Developer CLI がプレビューで利用出来るようになりました https://dev.classmethod.jp/articles/azure-developer-cli-preview/ azure 2022-07-13 00:38:16
技術ブログ Developers.IO Github Actionsを利用してAWS Lambdaに自動デプロイをしてみた https://dev.classmethod.jp/articles/lambda-github-actions/ awslambda 2022-07-13 00:36:50
海外TECH DEV Community Laravel delete actions simplified https://dev.to/jackmiras/laravel-delete-actions-simplified-4h8b Laravel delete actions simplifiedIn my last publishing mentioned controllers operations that frequently gets duplicated and how we could leverage what ve learned so far to make those operations simpler to use Now I would like to discuss another controller operation that frequently gets duplicated as well and that is the delete operation ContentConventional wayShortening itThe deleteOrFail functionAbstracting itTrait abstractionThe model functionThe deleteOrThrow functionCustom exceptionUsing the abstractionImplementing it Conventional wayBefore we jump into the simplification let s take a look at how a delete operation looks like when conventionally implemented lt phpnamespace App Http Controllers use App Models User use Illuminate Http Request use Illuminate Http Response class UsersController extends Controller public function destroy Request request Response user User find request gt id if user null return response User with id request gt id not found Response HTTP NOT FOUND if user gt delete false return response Couldn t delete the user with id request gt id Response HTTP BAD REQUEST return response id gt request gt id deleted gt true Response HTTP OK At the first line we are querying a user by its ID and storing the result into the user object Then at the first conditional we are checking if the user is null if it is it means that no record with the given ID got found and an error message with status will be responded Thereafter we have a second conditional where we are calling user gt delete this function returns true or false to let us know if the data got successfully deleted In case it returns false an error message with status will be responded Finally if the user got correctly deleted we render a response with the user s id and a property deleted with the value true Shortening itWhy not use the findOrFail helper function to shorten our code When using this approach it would remove at least five lines from the destroy action of our controller as shown in the code example down below lt phpnamespace App Http Controllers use App Models User use Illuminate Http Request use Illuminate Http Response class UsersController extends Controller public function destroy Request request Response user User findOrFail request gt id if user gt delete false return response Couldn t delete the user with id request gt id Response HTTP BAD REQUEST return response id gt request gt id deleted gt true Response HTTP OK At the first line we are querying a user by its ID using the findOrFail function This function has a special behavior where an exception gets thrown in case the data for the given ID didn t get found To make the most out of this change we need to know how to automate the handling of the exception thrown by the findOrFail Otherwise it would be necessary to use a try catch block and the number of lines would be pretty much the same As in the previous example we have a conditional where we are calling user gt delete into the user that we want to delete In case it returns false an error message with status will be responded Same as before if the user was deleted we render it s id and the property deleted with the value true The deleteOrFail functionNOTE This function will only be available if you are using Laravel on version or newer Now that we ve seen two different ways of implementing the delete action on Laravel let s see how we can implement this using the deleteOrFail function lt phpnamespace App Http Controllers use App Models User use Illuminate Http Request use Illuminate Http Response class Users extends Controller public function destroy Request request Response user User findOrFail request gt id if user gt deleteOrFail false return response Couldn t delete the user with id request gt id Response HTTP BAD REQUEST return response id gt request gt id deleted gt true Response HTTP OK As before we are querying a user by its ID using the findOrFail function Next we have a second conditional where we are calling user gt deleteOrFail this function returns true or false to let us know if the data got successfully deleted In case it returns false an error message with status will be responded Once more if the user got correctly deleted we render it s id and deleted as with the value true NOTE Notice that the deleteOrFail check if the model itself exists open a database connection then a transaction and call the delete function and the resultant usage is exactly the same as the one presented in the previous section This is a very odd implementation in the framework since most of the orFail functions usually throws an exception If that was the case we could just automate the handling of the exception thrown by the deleteOrFail function the same way we did in the last post from my series about exceptions If we had a standard orFail function this function would be the simplest way of implementing a destroy action in a controller completely removing the need for the approach that will be explained in the next section Abstracting itLet s see how we can abstract this implementation in a way that we get high reusability with simple usage out of this abstraction Since this abstraction interacts with models I wanted to avoid using inheritance because it would be a coupling too high for an abstraction as simple as this one Furthermore I want to leave the inheritance in the models open for usage whether by a team member decision or by some specific use case For that reason I ve chosen to implement the abstraction in a Trait Differently from C where we can use multiple inheritance in PHP a Trait is the mechanism to reduce limitations around single inheritance Besides that I have a personal rule where I use Traits only when an implementation gets highly reused since a good portion of my controllers end up having a destroy action in my context this is something highly reused Trait abstraction lt phpnamespace App Helpers use Illuminate Database Eloquent Model use App Exceptions ModelDeletionException trait DeleteOrThrow Instantiate a new model instance from the model implementing this trait return Model private static function model Model return new get class Find a model by id remove the model into the database otherwise it throws an exception param int id return Model throws App Exceptions ModelDeletionException public static function deleteOrThrow int id Model model self model gt findOrFail id if model gt delete false throw new ModelDeletionException id get class return model Our trait is compound of two functions model which is responsible for returning an instance of the model implementing the trait and deleteOrThrow which is responsible for delete the model or throw an exception in case delete fails Here we are simply implementing the behavior that I belive that would be the expected behavior for the new native deleteOrFail function in fact I used to call the deleteOrThrow function deleteOrFail but I had to rename it to not conflict with the deleteOrFail function implemented in Laravel The model function Instantiate the model implementing this trait by the model s class name return Model private static function model Model return new get class As mentioned this function is responsible for returning an instance of the model implementing the trait and since PHP allow us to use meta programming to instantiate classes let s take advantage of that and dynamically instantiate the model by its class name At this function we have a single line with a return statement that instantiate a new object out of the get class function To fully understand how this function works let s assume that this trait got implemented by the User model when evaluating the result of the function we would get a string App Models User When evaluated by the interpreter this line would be the equivalent to return new App Models User but the get class gives us the dynamism of getting the right class name for each model implementing the trait The deleteOrThrow function Find a model by id remove the model into the database otherwise it throws an exception param int id return Model throws App Exceptions ModelDeletionException public static function deleteOrThrow int id Model model self model gt findOrFail id if model gt delete false throw new ModelDeletionException id get class return model In the first line the self call indicates that we want to interact with the trait itself then we are chaining the model function to it which means we are calling the function previously defined Subsequently we have a conditional where we are calling user gt delete in case the function returns false a custom exception gets thrown Finally after a successful delete we return the deleted model Custom exceptionHere we are using the same technique explained in the Laravel custom exceptions post If you didn t read the post yet take a moment to read it so you can make sense out of this section lt phpnamespace App Exceptions use Illuminate Support Str use Illuminate Http Response class ModelDeletionException extends ApplicationException private int id private string model public function construct int id string model this gt id id this gt model Str afterLast model public function status int return Response HTTP BAD REQUEST public function help string return trans exception model not deleted help public function error string return trans exception model not deleted error id gt this gt id model gt this gt model At the class definition we are extending the ApplicationException which is an abstract class used to enforce the implementation of the status help and error functions and guarantee that Laravel will be able to handle this exception automatically Following the class definition we have the constructor where property promotion is being used to make the code cleaner As parameters we have id which contains the ID of the record we want to query from the database at our Trait and model where the full class name of the model can be found Inside the constructor we are extracting the model name out of the full class name the full name would be something like App Models User and we want just the User part This is getting done so we can automate the error message into something that makes sense to the person interacting with our API in case it s not possible to find the record of a given ID Next we have the implementation of the status function where we are returning the HTTP status Thereafter we have the help function where we are returning a translated string that indicates a possible solution to the error In case you are wondering the translated string would be evaluated to Check your deleting parameter and try again Finally we have the error function where the error that happened gets specified as in the previous function we are using a translated string but differently from before here we are using the replace parameters feature from trans This approach got chosen to give us a dynamic error message with context Here the translated string would be evaluated to something like User with id not deleted With this structure if the target model changes the message emitted by the exception would change as well since the model name gets dynamically defined As a secondary example imagine that now you are interacting with a Sale model in this case the message would automatically change to Sale with id not deleted Using the abstractionNow that our abstraction got defined and we guaranteed that the error handling was in place we need to use our DeleteOrThrow Trait in the models that we want to have this simplified delete behavior To achieve that we just have to put in our models the use DeleteOrThrow exactly like the other Traits that normally Laravel brings in the models you can see it with more details in the code example down below lt phpnamespace App Models use App Helpers DeleteOrThrow use Illuminate Database Eloquent Factories HasFactory use Illuminate Foundation Auth User as Authenticatable use Illuminate Notifications Notifiable use Laravel Sanctum HasApiTokens class User extends Authenticatable use HasFactory use Notifiable use HasApiTokens use DeleteOrThrow Implementing itAs a final result we end up with an API call that looks like User deleteOrThrow id leaving us with a destroy action in our controllers that has a single line of implementation and it is highly reusable lt phpnamespace App Http Controllers use App Models User use Illuminate Http Request use Illuminate Http Response class Users extends Controller public function destroy Request request Response return response User deleteOrThrow request gt id Happy coding 2022-07-13 00:52:51
海外TECH DEV Community freash look of ‘BUN’ https://dev.to/isaacxu18/a-5g67 freash look of BUN A few days back I found a new javasrcipt Runtime BUN It is very promising so I m going to make a overview about it What is BUN Bun is a baby javascript runtime created by Jarred Sumner a few days ago It is build on javascriptcore from WebKit Not like Bun other runtime like node and Deno are built on V Bun also have the potensial to replace node js and become the number one runtime Why BUNBun can do almost everything node js can do the only difference is Bun is faster than node js Being fast is pretty cool but the best part is that Bun is a all in one runtime It has a native module bundler which means that you can get rid of tools like webpack and also have a native transpiler that can allow you to write typescript and JSX out of the box It also have the abilities to download most npm times fast another fantastic feature of Bun that save you from installing DoteEVN everytime you open a project because Bun load those evnironment automatically How fast is BUNBun is the fastest Javascript runtime Way faster than the old Javascript runtimes node js and Deno We are talking about massive here just look at the graph down belowIt is about times faster when server rendering React and has a big difference in the other two as well InstallationTo install Bun on your PC go to your terminal and typecurl bashThank you to read my first blog I m a year old programmer That just started to write blog Please forgive me if I said anything wrong and if you have any suggest please comment down below or DM me on twitter twitter com Isaacxu Thank you 2022-07-13 00:13:34
海外科学 NYT > Science How NASA’s Webb Telescope Pictures Were Selected https://www.nytimes.com/2022/07/12/science/webb-telescope-pictures.html How NASA s Webb Telescope Pictures Were SelectedIn June specialists gathered in Baltimore to select images from the James Webb Space Telescope to share with the public Keeping the results to themselves hasn t been easy 2022-07-13 00:40:48
海外科学 NYT > Science Scientists Marvel at NASA Webb Telescope’s New Views of the Cosmos https://www.nytimes.com/live/2022/07/12/science/webb-telescope-images-nasa observatory 2022-07-13 00:42:19
海外TECH WIRED 25 Best Deals From Target’s ‘Deal Days’ Prime Day Rival Sale https://www.wired.com/story/target-deal-days-2022-prime-day-sale-1/ Best Deals From Target s Deal Days Prime Day Rival SaleAmazon Prime Day isn t the only sale this week From video games to household essentials here are our favorite picks from Target s big Deal Days sale of 2022-07-13 00:47:00
海外TECH WIRED These Must-Have MagSafe Accessories Are on Sale Right Now https://www.wired.com/story/anker-magsafe-maggo-accessories-prime-day-deals-2022/ prime 2022-07-13 00:22:24
海外科学 BBC News - Science & Environment Closest supermoon of the year to appear in sky https://www.bbc.co.uk/news/science-environment-62010265?at_medium=RSS&at_campaign=KARANGA closest 2022-07-13 00:54:11
医療系 内科開業医のお勉強日記 新型コロナウィルス感染とインフルエンザの同時複合感染の場合・・・インフルエンザウィルスが新型コロナウィルス複製を阻害 https://kaigyoi.blogspot.com/2022/07/blog-post_13.html このつのウイルスは、ヒトの気道に感染する能力が類似しており、重大な罹患率と死亡率をもたらす併発症が報告されている。 2022-07-13 00:47:00
医療系 内科開業医のお勉強日記 B型インフルエンザ・ユニバーサルワクチン登場? https://kaigyoi.blogspot.com/2022/07/b.html この結果は、構造安定化された定型抗原を組み込んだ層状タンパク質ナノ粒子が、免疫防御能と幅を改善した万能インフルエンザワクチンとなる可能性を示している。 2022-07-13 00:03:00
金融 ニッセイ基礎研究所 定年延長、試験導入(中国) https://www.nli-research.co.jp/topics_detail1/id=71773?site=nli 今般、江蘇省の趣旨としては、性別に関係なく、本人が希望し、雇用主が同意すれば最短で年から定年退職年齢の延長を可能とする、女性の一般労働者の定年退職年齢を歳から歳に引き上げる機会を増やす幹部職や管理職と同一にしていくといった点にあろう図表。 2022-07-13 09:55:25
ニュース BBC News - Home Sri Lanka: President Gotabaya Rajapaksa flees the country on military jet https://www.bbc.co.uk/news/world-asia-62132271?at_medium=RSS&at_campaign=KARANGA crisis 2022-07-13 00:50:30
ニュース BBC News - Home Covid: 3m adults still unvaccinated in England https://www.bbc.co.uk/news/health-62138545?at_medium=RSS&at_campaign=KARANGA covid 2022-07-13 00:14:57
北海道 北海道新聞 王位戦第2局、対局開始 定山渓温泉 https://www.hokkaido-np.co.jp/article/704988/ 定山渓温泉 2022-07-13 09:50:01
北海道 北海道新聞 英新首相争い、8人が立候補 前財務相ら有力、女性4人 https://www.hokkaido-np.co.jp/article/704990/ 首相 2022-07-13 09:47:00
北海道 北海道新聞 ツイッター、マスク氏提訴 「買収撤回は契約違反」 https://www.hokkaido-np.co.jp/article/704944/ 投稿サイト 2022-07-13 09:28:05
北海道 北海道新聞 東証、130円高 午前9時15分現在 https://www.hokkaido-np.co.jp/article/704984/ 日経平均株価 2022-07-13 09:38:00
北海道 北海道新聞 安倍氏メッセージ「見た」 容疑者、反感強めたか https://www.hokkaido-np.co.jp/article/704947/ 安倍晋三 2022-07-13 09:24:07
北海道 北海道新聞 ロマンスカー、虚偽予約の疑い 9千回か、40代の男性書類送検 https://www.hokkaido-np.co.jp/article/704978/ 小田急電鉄 2022-07-13 09:30:00
北海道 北海道新聞 ミャンマーと軍事協力強化 ロシア次官、国軍トップ会談 https://www.hokkaido-np.co.jp/article/704975/ 軍事協力 2022-07-13 09:25:00
北海道 北海道新聞 レゴ、ロシア事業を無期限停止 店舗運営企業との契約打ち切り https://www.hokkaido-np.co.jp/article/704974/ 店舗運営 2022-07-13 09:24:00
北海道 北海道新聞 スリランカ大統領、国外脱出 軍用機でモルディブに https://www.hokkaido-np.co.jp/article/704968/ 経済危機 2022-07-13 09:12:00
ビジネス 東洋経済オンライン 日本人は「生物多様性」のど真ん中に生きている 茶道の文化から「命のつながり」が見えてくる | リーダーシップ・教養・資格・スキル | 東洋経済オンライン https://toyokeizai.net/articles/-/601792?utm_source=rss&utm_medium=http&utm_campaign=link_back 日本文化 2022-07-13 09:30:00
ビジネス プレジデントオンライン 「離党しても除名されても死ぬ前には戻りたい」自民党に有象無象の議員が沢山いる本当の理由 - 自民党で最後を迎えることが強さの証明 https://president.jp/articles/-/59503 有象無象 2022-07-13 10:00:00
ビジネス プレジデントオンライン 「8分遅刻しただけで昇進が消えた」"うっかり寝坊した駅員"を待ち受ける大きな代償 - 元JR職員が明かす「安全以上に時間に厳しい」理由 https://president.jp/articles/-/59439 日本の鉄道 2022-07-13 10:00:00
IT 週刊アスキー 【本日】スシロー価格改定前大盤振る舞い「100円(110円)祭」スタート https://weekly.ascii.jp/elem/000/004/097/4097765/ 大盤振る舞い 2022-07-13 09:30:00
IT IT号外 シャオミー(xiaomi)のスマホ、音声通話(電話着信)ができない!データ通信(インターネット)が繋がらない!連絡帳の同期ができない!僕はとんでもねぇモノを選んでしまったのだろうか? https://figreen.org/it/%e3%82%b7%e3%83%a3%e3%82%aa%e3%83%9f%e3%83%bcxiaomi%e3%81%ae%e3%82%b9%e3%83%9e%e3%83%9b%e3%80%81%e9%9f%b3%e5%a3%b0%e9%80%9a%e8%a9%b1%e9%9b%bb%e8%a9%b1%e7%9d%80%e4%bf%a1%e3%81%8c%e3%81%a7%e3%81%8d/ シャオミーxiaomiのスマホ、音声通話電話着信ができないデータ通信インターネットが繋がらない連絡帳の同期ができない僕はとんでもねぇモノを選んでしまったのだろうか中国製スマホ、シャオミーの使用を開始してヶ月となったが、ここにきてとんでもない事態が発生しました。 2022-07-13 00:23:55
ニュース THE BRIDGE 共働きの家計管理「ペアカード」がハマったB/43、スマートバンクが20億円調達 https://thebridge.jp/2022/07/smartbank-raised-2b-yen 共働きの家計管理「ペアカード」がハマったB、スマートバンクが億円調達ニュースサマリ家計支出管理サービスを展開するスマートバンクは月日、新たな増資の公表を実施している。 2022-07-13 00:03:01

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)