register.blade.phpをadminユーザーのみアクセルできるようにする

①AuthServiceProviderでGateの設定 Gate::define('admin', function($user) { foreach($user->roles as $role){ if($role->name=='admin') { return true; } } return false; });②ルート設定(web.php)でミドルウェエア適用Route::middleware(['auth', 'can…

デプロイ後の反映

コミット↓プッシュ↓プル ターミナル起動 ↓ Xサーバーに接続 ↓ 本番環境のディレクトリに移動 ↓ git pull

gitLab接続方法

【gitLab】プロジェクトページ ⇒ クローン ⇒ HTTPSでクローンをコピー 【fork】Remotes右クリック ⇒ Add new remote ⇒ HTTPSでクローンをコピーの貼り付け 【fork】コミット ⇒ push ○各々で開発する方法テスト 【gitLab】HTTPSでクローンをコピー 【fork】fi…

Forkの使い方

○リポジトリ作成ファイル→newリポジトリ ○.gitignore# OS依存のシステムファイル #Thumbs.db.DS_Store.fseventsd.Spotlight-V100.Trashes ○ファイルを修正したらlocal changes↓stage↓commite(checkoutすることで行ったり来たりできる)↓all commits ○フォルダ…

error: Your local changes to the following files would be overwritten by merge:

1) リモートの最新を取ってくる$ git fetch origin master # 2) masterを強制的に合わせる$ git reset --hard origin/master 参考WEBページ qiita.com

mail設定

★★★.envファイルにメール送信のための設定★★★ MAIL_ADMIN=○○@○○ Laravel Sailの場合 http://localhost:8025/ ★★★CONFIGファイルの設定(configの中の mail.phpファイル)★★★ admin'=>env('MAIL_ADMIN', null), ★★★ContactContoroller.php★★★ use Illuminate\S…

Forkの使い方

○リポジトリ作成ファイル→newリポジトリ ○.gitignore# OS依存のシステムファイル #Thumbs.db.DS_Store.fseventsd.Spotlight-V100.Trashes ○ファイルを修正したらlocal changes↓stage↓commite(checkoutすることで行ったり来たりできる)↓all commits ○フォルダ…

return view('cart.index');とreturn redirect()->route('cart.index');の違い

return view('cart.index'); の場合: 直接ビューへのアクセス: このコマンドはサーバーに対して、直接 cart.index ビューをクライアント(ユーザーのブラウザ)に表示するよう指示します。 データの渡し方: コントローラーからビューへ直接データを渡すこと…

カート作成

ビュー(/show.blade.php) use App\Http\Controllers\CartController; $quantity = Stock::where('post_id', $post->id) ->sum('quantity'); if($quantity > 9){ $quantity = 9; } <form method="post" action="{{ route('cart.add')}}"> @csrf <div class="flex items-center"> <select name="quantity class=""> </select></div></form>

送料180円を加える

public function start() { $stripe = new \Stripe\StripeClient(config('services.stripe.st_key')); $url = 'http://127.0.0.1:8000'; $id = auth()->user()->id; $session = $stripe->checkout->sessions->create([ 'payment_method_types' => ['card'], …

プルダウンメニューで選択された数量の値をStripeへ渡す

var stripe = Stripe("{{config('services.stripe.pb_key')}}");var checkoutButton = document.getElementById('checkout-button');var displayError = document.getElementById('error-message');var quantitySelect = document.getElementById('quantity'…

選択可能な数量を制限する方法

各商品にはstockのような属性があると仮定します。このstock属性は商品の在庫数を表します。商品の詳細ページに遷移したとき、stock属性を使用して、選択できる数量を制限します。在庫が0の場合、カートに入れるボタンを無効化し、「現在在庫が切れています…

Webhookのペイロードから情報を取得する方法

public function handleWebhook(Request $request) { $payload = $request->all(); $amount = $payload['data']['object']['amount']; // 「誰が」購入したかの情報を取得 $user_name = $payload['data']['object']['user_name']; // 「どの商品」を購入した…

Stripeを使用して、特定の数量分の商品を発注する方法

前提条件:Stripeアカウントを既に持っていること。Laravelプロジェクトが既にセットアップされていること。手順:1. Stripe PHP SDKのインストール Laravelプロジェクトのルートディレクトリで以下のコマンドを実行して、Stripe PHP SDKをインストールします…

バリデーションチェック

① public function store(Request $request){ // バリデーションのルールを設定 $request->validate([ 'pickup_time.*' => 'required|date_format:H:i', 'pickup_location.*' => 'required|string', 'dropoff_time.*' => 'required|date_format:H:i', 'dropo…

多対多リレーション

artisan make:migration create_roles_users_table --create=role_user 中間テーブルは、2つのモデルのモデル名をアルファベット順に並べるというルールがある。 【User.php】 public function roles() { return $this->belongsToMany(Role::class); } 【Ro…

主なsail artisan

sail artisan make:migration add_column_user_id_to_posts_table --table=posts sail artisan make:model Post -m sail artisan make:controller PostController --resource --model=Post

編集するファイルの在りか

ログイン後の画面app/Providers/RouteServiceProvide.php メニューの追加resources/views/layoutsの中のnavigation.blade.php ログインと登録ページへのリンクを追加resources/views/layouts/guest.blade.php ログイン画面・登録画面のロゴresources/views/c…

パラメータ情報の受け渡し

【a.blade.php】<a href="{{route('b', $○○)}}"></a> 【Controller.php】 public function show(Post $○○) { return view('b', compact('○○')); }【b.blade.php】 {{ $○○->title }}

投稿の削除

【view】 <x-primary-button class="bg-red-700 float-right ml-4" onClick="return confirm('本当に削除しますか?');">削除</x-primary-button> 【Controller】 public function destroy(Post $post) { $post->delete(); return redirect()->route('post.index')->with('message', '投稿を削除しました'); }

データベース

●データベースの中から、条件に合うデータを取得する モデル名::where('テーブルのカラム名', 条件)->get(); 例) $posts=Post::where('user_id', $user)->get();

全文表示させない

{{$post->body}}↓{{Str::limit($post->body, 100, '...')}}

アプリ名を変更

envファイルの1行目の APP_NAME=の後を変更する。

画像の挿入

<img src="{{asset('○○/○○.png')}}" style="max-height:80px;"> asset関数を使う。asset関数を用いることで、publicにアクセスできる。

Componentの作成

Componentの作成:php artisan make:component コンポーネント名 ☆活用例 【app/View/Components/コンポーネント名.php】classコンポーネント名 extends Component{ public $○○; public function __construct($○○) { $this->○○ = $○○; } 【resources/views/c…

日付表示

○スラッシュで区切る{{$post->created_at->format('Y/m/d')}} ○日本語表示{{$post->created_at->format('Y年m月d日')}} ちなみに、 データを日付として表示すにには、date型にして保存しておく。 マイグレーションファイルで、あらかじめdate型に設定してお…

バリデーション

readouble.com ○例 'title'=>'required|max:255','body'=>'required|max:1000', 'image'=>'image|max:1024' ○'end_date' => 'after:start_date' 'end_date' フィールドの値は、'start_date' フィールドの値の後になる。例えば、終了日が開始日の後になるかど…

Attempt to read property "name" on null

resources/views/layouts/app.blade.php 【navigation.blade.php】Auth:: で始まるコード3か所を以下のように修正 <div>@if(Auth::check()) {{ Auth::user()->name }} @endif</div> <div class="font-medium text-base text-gray-800">@if(Auth::check()) {{ Auth::user()->name }} @endif</div>

リソースコントローラー

Route::resource('post', PostController::class);↓ Route::get('post', [PostController::class, 'index'])->name('post.index');Route::get('post/create', [PostController::class, 'create'])->name('post.create');Route::post('post', [PostController…

migrate操作一覧

《基本の流れ》 【ターミナル】 php artisan make:migration add_column_カラム名_to_テーブル名_table --table=テーブル名 【マイグレーションファイル】 public function up() { と public function down() { に希望の操作を記述 【ターミナル】 php artis…