2023-08-10から1日間の記事一覧

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

【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' フィールドの値の後になる。例えば、終了日が開始日の後になるかど…