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)の開発
回答2件
あなたの回答
tips
プレビュー