ところで、ゼロ埋めってどうやるのか?
$id = 2;
$order_id = sprintf("%05d", $id);
echo $id . "<br>";
echo $order_id;
sprintfを使えばいいのね。なるほど。
随机应变 ABCD: Always Be Coding and … : хороший
ところで、ゼロ埋めってどうやるのか?
$id = 2;
$order_id = sprintf("%05d", $id);
echo $id . "<br>";
echo $order_id;
sprintfを使えばいいのね。なるほど。
web.php
use App\Events\Logined;
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
event(new Logined());
})->name('dashboard');
mysql> select * from users;
LoginControllerがなくても、public const HOME = ‘*’; で処理すればいいだけね。
凄い悩んでたのに、一瞬で解決しました。
公式サイトのサンプルでテストします。
<a href="/test.html">
<div class="card" style="width: 18rem;">
<svg class="bd-placeholder-img card-img-top" width="100%" height="180" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: Image cap"><title>Placeholder</title><rect fill="#868e96" width="100%" height="100%"/><text fill="#dee2e6" dy=".3em" x="50%" y="50%">Image cap</text></svg>
<div class="card-body">
<h5 class="cart-title">Cart Title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</a>
普通にaタグで囲うだけでOKです。

こういうbelongTo->belongToが出来るのか試したが、結論から言うと出来る。
<p>{{ $orders->product->category->name }}</p>
model: productがcategoryのbelongTo
public function category(){
return $this->belongsTo('App\Models\Category');
}
model: orderがproductのbelongTo
public function product(){
return $this->belongsTo('App\Models\Product', );
}
良かったー 死ぬかと思った。。
<style>
table {
width: 100%;
}
th, td {
height: 300px;
vertical-align: middle;
padding: 0 15px;
border: 1px solid #ccc;
}
.fixed01 {
position: sticky;
top: 0;
color: #FFF;
background: #333;
&:before{
content: "";
position: absolute;
top: -1px;
left: -1px;
width: 100%;
height: 100%;
border: 1px solid #ccc;
}
}
</style>
</head>
<body>
<div class="container">
<table>
<tr>
<th class="fixed01">見出し</th>
<th class="fixed01">見出し</th>
<th class="fixed01">見出し</th>
</tr>
<tr>
<td>テキスト</td>
<td>テキスト</td>
<td>テキスト</td>
</tr>
<tr>
<td>テキスト</td>
<td>テキスト</td>
<td>テキスト</td>
</tr>
</table>
</div>
「position: sticky;」は「指定された場所までいくと固定」される仕様

なるほど。。
$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、大体テストしたいことはテストできた。