$products = DB::table('products')->where('name', 'like', '%'.$query.'%')->orWhere('amount', 'like', '%'.$query.'%')->Paginate(4);
単純にorWhereを繋げるだけです。
OK, スッキリした。
随机应变 ABCD: Always Be Coding and … : хороший
$products = DB::table('products')->where('name', 'like', '%'.$query.'%')->orWhere('amount', 'like', '%'.$query.'%')->Paginate(4);
単純にorWhereを繋げるだけです。
OK, スッキリした。
財務省の見解
「税抜価格」に上乗せする消費税相当額に1円未満の端数が生じる場合がありますが、その端数をどのように処理 (切捨て、切上げ、四捨五入など)して「税込価格」を設定するかは、それぞれの事業者のご判断によることとなります。
え? 要するになんでもいいの?
phpで計算するとき。
$price = 5678; echo $price * 0.1;
-> 567.8
$price = 5678; echo floor($price * 0.1) . "<br>"; // 切り捨て echo ceil($price * 0.1) . "<br>"; // 切り上げ echo round($price * 0.1) . "<br>"; // 四捨五入
567
568
568
切捨て、切上げ、四捨五入 どれでも対応はできるようです。って当たり前か。
$ php artisan make:migration add_column_last_login_at_users_table –table=users
migration
public function up() { Schema::table('users', function (Blueprint $table) { // $table->timestamp('last_login_at')->nullable()->after('remember_token')->comment('最終ログイン'); }); }
$ php artisan migrate
app/Providers/EventServiceProvider.php
protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, ], 'App\Events\Logined' => [ 'App\Listeners\LastLoginListener', ], ];
$ php artisan event:generate
app/Listeners/LastLoginListener.php
public function handle(Logined $event) { $user = Auth::user(); $user->last_login_at = Carbon::now(); $user->save(); }
### test
use App\Events\Logined; public function testForm(){ event(new Logined()); return view('admin.test'); }
$ php artisan serve –host 192.168.33.10 –port 8000
http://192.168.33.10:8000/admin/test/form
mysql> select * from users;
問題は、このevent(new Logined());をどこで仕込むかやな。。。
Laravel8系だとLoginControllerがない。。。。
というか、もっと優先順位が高い事が入ったーーーーーーーーーーー
公式説明: https://readouble.com/laravel/8.x/ja/sanctum.html
https://laravel.com/docs/8.x/authentication
At its core, Laravel's authentication facilities are made up of "guards" and "providers". Guards define how users are authenticated for each request. For example, Laravel ships with a session guard which maintains state using session storage and cookies. Providers define how users are retrieved from your persistent storage. Laravel ships with support for retrieving users using Eloquent and the database query builder. However, you are free to define additional providers as needed for your application.
うーん、ちょっとよくわからんな。
vendor/laravel/framework/src/illuminate/Auth で処理してるのはわかるんだが、どこにイベントを追加すれば良いのか。。。
まずフォームとcontrollerを用意します。
<form action="/admin/test" method="post"> {{ csrf_field() }} <input type="text" name="name"> <input type="submit" value="送信"> </form>
public function test(Request $request){ $validatedData = $request->validate([ 'name' => ['string'], ]); dd($validatedData); }
1. “string”のバリデーションで数字のみのチェックは通すか?
-> OK
2. minとmaxが同数の場合(桁数を指定)
$validatedData = $request->validate([ 'name' => ['min:9','max:9'], ]);
-> OK
3. alpha_dashで数字のみ
-> OK
4. textareaで改行を含めた文字でpostした場合
-> ちゃんと”\r\n”で入ってますね。
OK、大体テストしたいことはテストできた。
Kibanaで、以下の様にアラートが出ているので、7系から5系にダウングレードする。
This version of Kibana requires Elasticsearch v5.6.16 on all nodes. I found the following incompatible nodes in your cluster: v7.10.1 @ 127.0.0.1:9200 (127.0.0.1)
$ yum remove elasticsearch
$ cd /etc/yum.repos.d/
[elasticsearch-5.x] name=Elasticsearch repository for 5.x packages baseurl=https://artifacts.elastic.co/packages/5.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md
$ sudo yum install elasticsearch-5.6.16
$ sudo vi /etc/elasticsearch/jvm.options
-Xms256m -Xmx256m
$ sudo service elasticsearch start
$sudo vi /etc/elasticsearch/elasticsearch.yml
network.host: 0.0.0.0
$ sudo service elasticsearch start
Starting elasticsearch (via systemctl): [ OK ]
$ sudo systemctl status elasticsearch -l
localhost elasticsearch[28744]: OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
何故だ? さっぱりわからん。。。
公式サイトを参考にします。
https://www.elastic.co/guide/jp/kibana/current/rpm.html
$ cd /etc/yum.repos.d
$ ls
$ sudo touch kibana.repo
$ sudo vi kibana.repo
[kibana-5.x] name=Kibana repository for 5.x packages baseurl=https://artifacts.elastic.co/packages/5.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md
$ sudo yum install kibana
$ sudo vi /etc/kibana/kibana.yml
server.host: "0.0.0.0"
$ sudo service kibana start
kibana started
http://192.168.33.10:5600/
あれ?
$ sudo vi /etc/kibana/kibana.yml
server.port: 5601 server.host: "192.168.33.10" elasticsearch.url: "http://localhost:9200"
$ sudo service kibana restart
http://192.168.33.10:5601/
何これ、やべえ、インフラ構成見直そう。
あれ、何か出てる
This version of Kibana requires Elasticsearch v5.6.16 on all nodes. I found the following incompatible nodes in your cluster: v7.10.1
Elasticsearchとkibanaは同じバージョンを使わなければならないとのこと。。うーん、困った。
Logstash: ログの収集と記録のための機能を備えており、プラグイン形式で機能を拡張できる
Elastic Search: オープンソースで開発されている分散型データベース、 リアルタイムでのデータ分析や検索機能に優れている
Kibana: Elasticsearch内に格納されているデータを可視化できる
ELKには、Java Runtime Environment(JRE)が必要で、openjdkで提供されている。
ログ収集のパフォーマンスはLogstashよりfluentdの方が優れている?
$ cat /etc/system-release
Amazon Linux release 2 (Karoo)
$ sudo yum update -y
### Java Install
$ sudo yum search java
$ sudo yum install java-1.8.0-openjdk-devel.x86_64
$ java -version
openjdk version “1.8.0_265”
OpenJDK Runtime Environment (build 1.8.0_265-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
$ javac -version
javac 1.8.0_265
## ELKインストール
ElasticSearch -> Kibana -> logstash の順にインストールしていく
### Elastic Search
こちらのサイトを参考にする
https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html
$ sudo rpm –import https://artifacts.elastic.co/GPG-KEY-elasticsearch
$ cd /etc/yum.repos.d/
$ sudo touch elasticsearch.repo
$ sudo vi elasticsearch.repo
[elasticsearch] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=0 autorefresh=1 type=rpm-md
$ sudo yum install –enablerepo=elasticsearch elasticsearch
$ sudo cat /etc/elasticsearch/jvm.options
-> Xms1g, Xmx1gを -Xms256m、-Xmx256m に変更する
# Xms represents the initial size of total heap space # Xmx represents the maximum size of total heap space -Xms1g -Xmx1g
$ sudo service elasticsearch start
ん? failed
$ sudo systemctl status elasticsearch -l
12月 15 19:05:52 localhost systemd-entrypoint[22869]: OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000801511000, 131072, 0) failed; error=’Not enough space’ (errno=12)
何だと??
$ sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
$ sudo /sbin/mkswap /var/swap.1
$ sudo /sbin/swapon /var/swap.1
$ free
$ sudo service elasticsearch start
Starting elasticsearch (via systemctl): [ OK ]
きゃああああああああああああああああああああああああああああああ
$ curl localhost:9200/
うおおおおおおおお、酒飲みてえええええええええええ
v-modelはselect boxでも基本はinput textと同じ。
初期値をセットする。
<?php $value = "4m,6m,9m,12m"; $data = explode(",",$value); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="app"> <?php echo "<select v-model=\"size\" name=\"hoge\">"; foreach($data as $value){ echo "<option value=\"" .$value. "\">" .$value. "</>"; } echo "</select>"; ?> <br><br> <form action="#" method="POST"> <input type="text" name="size" v-model="size"> <button type="submit" class="btn btn-default btn-order">送信</button> </form> </div> <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script> <script> new Vue({ el: '#app', data: { size: '<?php echo $data[0]; ?>', } }) </script> </body> </html>
OKでしょう。
Vueもいいが、Reactでちゃんとアプリを作りたいな。
View
-> pagingは $products->appends(request()->input())->links(”)とする
<h1>Get Method Test</h1> <form action="/admin/show" method="get"> <div class="form-group"> <label for="text1">Product:</label> <div class="row"> <input type="text" id="text1" name="search" class="form-control col-md-2" style="margin-left:15px"> <input type="submit" class="btn btn-primary"> </div> </div> </form> <p>{{ $query ? '「' .$query. '」' : '' }}<p> @foreach($products as $product) <p>{{ $product->name}}</p> @endforeach {{-- Pagination --}} <div class="d-flex justify-content-center"> {!! $products->appends(request()->input())->links('') !!} </div>
controller
-> 部分一致は’%’.$query.’%’と書く。 %$query%と書かない様に注意
public function show(Request $request){ $query = $request->get('search'); if($query !== Null){ $products = DB::table('products')->where('name', 'like', '%'.$query.'%')->Paginate(4); } else { $products = DB::table('products')->Paginate(4); } return view('admin.show', compact('products','query')); }
取り敢えずページングはOKっぽい。
続いてメール周りを整理する。Let’s Gooooooooooo