アプリ関連ニュース
- 2022年5月20日
- 技術情報
知っておいていただきたいこと – 5
今回も、Laravelの知っておいた方がいいとおもったことをいくつか紹介します。
Laravel Tip #findMany
Laravelのfindメソッドは知っていますが、このfindManyメソッドでidから複数のデータを取得できることはご存知でしょうか?
$user = User::findMany([1, 2, 3]);
// Select * From users Where id IN (1,2,3)
findManyメソッドには、オプションの第2パラメータがあり、これを使用して取得したいカラムを指定することができます。
$users = User::findMany([1,2,3],['id','name']);
//Select id, name From users Where id IN (1,2,3)
ということで、今回はこれで終わります。
金曜担当 – Ami
asahi at 2022年05月20日 10:00:00
- 2022年5月19日
- 技術情報
[JavaScript] Formの入力内容をObject形式で取得する
Ajaxなどでフロントエンドからサーバーサイドと連携する際に
Object形式でサーバーサイドにパラメータをpostします。
そのような場合に、Formの入力内容をまとめてObject形式で取得する方法が
便利なのでシェアしたいと思います。
nishida at 2022年05月19日 10:00:00
- 2022年5月17日
- 技術情報
Converting XML to Array with PHP
Today, I would like to share about converting xml data to associated array in PHP. Let’s take a look.
We will need just 4 steps to perform that.
Step 1 : read the xml file and get file contents.
<?php
// read xml file
$xmlFile = "sample.xml";
$xmlFileContents = file_get_contents($xmlFile);
Step 2 : convert xml data into xml object.
// Convert XML Data into XML Object
$xmlObject = simplexml_load_string($xmlFileContents);
Step 3 : convert xml object to Associated array
// Convert XML data object to Array
$json = json_encode($xmlObject);
$array = json_decode($json, true);
Step 4 : print the result
// print array
print "<pre>";
print_r($array);
print "</pre>";
This is all for now. Hope you enjoy that.
By Asahi
waithaw at 2022年05月17日 10:00:00
- 2022年5月16日
- 技術情報
Deleting a Git branch locally and remotely
You may have accidentally created a local branch or a remote branch on your local machine or remote host, respectively. In other cases, you may simply want to delete the local or remote branch.
Delete the local branch
To delete a local Git branch, you need to specify the –delete or -d flag in your git branch command (the latter is just an alias for –delete).
$ git branch --delete local-branch
Or you can also use like this
$ git branch -d local-branch
As for force deleting , you can use like this
$ git branch -D my-local-branch-name
Delete a Remote Branch
You can delete a remote branch using as below.
$git push origin --delete remote-branch
Now, once the remote branch is removed from the remote host, you need to make sure that the other machines are also in sync. The branch has been removed from both the local machine and the remote host, but other machines may still have the old tracking branch. This can be listed by running git branch -a
.
To ensure that all machines are in-sync, you need to run
$git fetch --all --prune
Yuuma
yuuma at 2022年05月16日 10:00:00
- 2022年5月13日
- 技術情報
知っておいていただきたいこと – 4
今回も、Laravelの知っておいた方がいいとおもったことをいくつか紹介します。
Laravel Tip
ここでは、クエリを少し読みやすくするための小さな工夫を紹介します。あるオブジェクトに「属している」レコードを問い合わせる際には、 ‘whereBelongsTo’ メソッドを使用します。
$article = Article::where('user_id', $user->id)->paginate(10);
//After
$article = Article::whereBelongsTo($user)->paginate(10);
ということで、今回はこれで終わります。
金曜担当 – Ami
asahi at 2022年05月13日 10:00:00