質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

Q&A

解決済

2回答

2507閲覧

LaravelでViewを変更したけど、反映されない(初心者なのでお手柔らかにお願いします)

bluepiani0788

総合スコア51

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

1グッド

0クリップ

投稿2022/03/23 13:54

stores/index.blade.phpのビューを参考にして、テーブルタグを利用しusers/index.blade.phpをユーザー名、メールアドレスを表示するように変更したいです。
イメージ説明

実現したいこと

上図は元の画面。クーポン、都道府県などが消えてメールアドレスになる予定。

発生している問題・エラーメッセージ

自分では書いたつもりでブラウザを更新しても画面に変化なし。web.phpも書きました。コントローラーからビューにデータを渡す処理までは作成してある状態です。なぜ、画面更新されないんでしょう?

該当のソースコード

参考のstores/index.blade.php

@extends('dashboard-layout') @section('content') <h1>店舗一覧</h1> <a href="{{ route('admin.stores.create') }}" class="btn btn-success">作成</a> <table class="table"> <thead> <tr> <th class="text-center">#</th> <th>店舗名</th> {{--<th>クーポン</th>--}} <th>url</th> </tr> </thead> <tbody> @foreach($stores as $store) <tr> <td class="text-center">{{ $store->id }}</td> <td>{{ $store->name }}</td> {{--<td>Develop</td>--}} <td><a href="{{ $store->url }}" target="_blank">{{ $store->url }}</a></td> <td class="td-actions text-right"> {{--<button type="button" rel="tooltip" class="btn btn-info">--}} {{--<i class="material-icons">person</i>--}} {{--</button>--}} <button type="button" rel="tooltip" class="btn btn-success"> <a href="{{ route('admin.stores.edit', [$store->id]) }}" class="text-white"><i class="material-icons">edit</i></a> </button> <button type="button" rel="tooltip" class="btn btn-danger"> <i class="material-icons">close</i> </button> </td> </tr> @endforeach </tbody> </table> @endsection

新たに作成したusers/index.blade.php

@extends('dashboard-layout') @section('content') <h1>ユーザー一覧</h1> <a href="{{ route('admin.users.create') }}" class="btn btn-success">作成</a> <table class="table"> <thead> <tr> <th class="text-center">#</th> <th>ユーザー名</th> <th>メールアドレス</th> </tr> </thead> <tbody> @foreach($users as $user) <tr> <td class="text-center">{{ $user->id }}</td> <td>{{ $user->name }}</td> <td>{{ $user->mail }}</td> {{--<td>Develop</td>--}} <td class="td-actions text-right"> {{--<button type="button" rel="tooltip" class="btn btn-info">--}} {{--<i class="material-icons">person</i>--}} {{--</button>--}} <button type="button" rel="tooltip" class="btn btn-success"> <a href="{{ route('admin.users.edit', [$user->id]) }}" class="text-white"><i class="material-icons">edit</i></a> </button> <button type="button" rel="tooltip" class="btn btn-danger"> <i class="material-icons">close</i> </button> </td> </tr> @endforeach </tbody> </table> @endsection

web.php

<?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return view('welcome'); }); Auth::routes(); Route::get('/home', 'HomeController@index')->name('home'); Route::group(['prefix' => 'admin', 'as' => 'admin.', 'namespace' => 'Admin'], function () { Route::get('/', function () { return view('admin.dashboard-home'); }); Route::group(['prefix' => 'stores', 'as' => 'stores.'], function () { Route::get('/', 'StoreController@index')->name('index'); Route::get('create', 'StoreController@create')->name('create'); Route::get('{store}/edit', 'StoreController@edit')->name('edit'); Route::patch('{store?}', 'StoreController@update')->name('update'); Route::put('{store?}', 'StoreController@update')->name('create.exec'); }); Route::group(['prefix' => 'coupons', 'as' => 'coupons.'], function () { Route::get('/', 'CouponController@index')->name('index'); Route::get('create', 'CouponController@create')->name('create'); Route::get('{coupon}/edit', 'CouponController@edit')->name('edit'); Route::patch('{coupon?}', 'CouponController@update')->name('update'); Route::put('{coupon?}', 'CouponController@update')->name('create.exec'); Route::get('{coupon?}', 'CouponController@detail')->name('detail'); }); Route::group(['prefix' => 'users', 'as' => 'users.'], function () { Route::get('/', 'UserController@index')->name('index'); Route::get('create', 'UserController@create')->name('create'); Route::get('{user}/edit', 'UserController@edit')->name('edit'); Route::patch('{user?}', 'UserController@update')->name('update'); Route::put('{user?}', 'UserController@update')->name('create.exec'); }); });

コントローラ

<?php namespace App\Http\Controllers\Admin; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Service\UserService; //追加 use Illuminate\Support\Facades\DB; use App\Models\User; class UserController extends Controller { private $user_service; public function __construct(UserService $user_service) { $this->user_service = $user_service; } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $users = $this->user_service->getAllUsers(); return view('admin.dashboard-users-archive', compact('users')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // } }

試したこと

php artisan migrate:refreshによるリフレッシュ
使用ブラウザ(FireFox)のキャッシュクリア

補足情報(FW/ツールのバージョンなど)

・自分のパソコン(Windows10)にDockerをインストール
・Laravel5.8.38(PHP)の開発

AbeTakashi👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

アクセスは http://localhost/admin/users にしてます。
UserControllerの一部を
public function index(Request $request)
{
$users = $this->user_service->getAllUsers();
return view('admin.users.index', ['users' => User::query()->paginate()]);
}
に変更したらできました。
ありがとうございます。

投稿2022/03/24 06:35

bluepiani0788

総合スコア51

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

どのURLでアクセスしてますか?
ちなみにadmin/usersのアクセスは、admin.dashboard-users-archiveをViewで指定してるので、users/index.blade.phpを表示したいなら、users.indexを指定する必要があります。

投稿2022/03/23 14:20

編集2022/03/23 23:25
ryyy

総合スコア30

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問