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

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

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

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

Laravel 5

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

Q&A

解決済

1回答

886閲覧

tweet機能の作成を練習しています。php artisan db:seedでseederを実行すると、Class 'App\Model\User' not found

jiro-

総合スコア28

PHP

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

Laravel 5

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

0グッド

0クリップ

投稿2019/12/15 14:56

編集2019/12/16 01:01

前提・実現したいこと

リンク内容
このサイトを参考にtweet機能の作成を練習しています。

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

$php artisan db:seed すると Class 'App\Models\User' not found が発生します。

該当のソースコード

CreateUsersTable

1<?php 2 3use Illuminate\Support\Facades\Schema; 4use Illuminate\Database\Schema\Blueprint; 5use Illuminate\Database\Migrations\Migration; 6 7class CreateUsersTable extends Migration 8{ 9 /** 10 * Run the migrations. 11 * 12 * @return void 13 */ 14 public function up() 15 { 16 Schema::create('users', function (Blueprint $table) { 17 $table->bigIncrements('id'); 18 $table->string('screen_name')->unique()->null()->comment('アカウント名'); 19 $table->string('name')->comment('ユーザー名'); 20 $table->string('profile_image')->nullable()->comment('プロフィール画像'); 21 $table->string('email')->unique(); 22 $table->timestamp('email_verified_at')->nullable(); 23 $table->string('password'); 24 $table->rememberToken(); 25 $table->timestamps(); 26 }); 27 } 28 29 /** 30 * Reverse the migrations. 31 * 32 * @return void 33 */ 34 public function down() 35 { 36 Schema::dropIfExists('users'); 37 } 38}

App\user.php

1<?php 2 3namespace App\Models; 4 5use Illuminate\Notifications\Notifiable; 6use Illuminate\Contracts\Auth\MustVerifyEmail; 7use Illuminate\Foundation\Auth\User as Authenticatable; 8 9class User extends Authenticatable 10{ 11 use Notifiable; 12 13 /** 14 * The attributes that are mass assignable. 15 * 16 * @var array 17 */ 18 protected $fillable = [ 19 'screen_name', 20 'name', 21 'profile_image', 22 'email', 23 'password', 24 ]; 25 26 /** 27 * The attributes that should be hidden for arrays. 28 * 29 * @var array 30 */ 31 protected $hidden = [ 32 'password', 'remember_token', 33 ]; 34 35 /** 36 * The attributes that should be cast to native types. 37 * 38 * @var array 39 */ 40 protected $casts = [ 41 'email_verified_at' => 'datetime', 42 ]; 43 44 45 public function followers() 46 { 47 return $this->belongsToMany(self::class, 'followers', 'followed_id', 'following_id'); 48 } 49 50 51 public function follows() 52 { 53 return $this->belongsToMany(self::class, 'followers', 'followed_id', 'following_id'); 54 } 55} 56

databease\seeds\UsersTableSeeder

1<?php 2 3use Illuminate\Database\Seeder; 4use App\Models\User; 5 6class UsersTableSeeder extends Seeder 7{ 8 /** 9 * Run the database seeds. 10 * 11 * @return void 12 */ 13 public function run() 14 { 15 for ($i = 1; $i <= 10; $i++) { 16 User::create([ 17 'screen_name' => 'test_user' .$i, 18 'name' => 'TEST' .$i, 19 'profile_image' => 'https://placehold.jp/50x50.png', 20 'email' => 'test' .$i .'@test.com', 21 'password' => Hash::make('12345678'), 22 'remember_token' => str_random(10), 23 'created_at' => now(), 24 'updated_at' => now() 25 ]); 26 } 27 } 28}

config\auth.php

1<?php 2 'providers' => [ 3 'users' => [ 4 'driver' => 'eloquent', 5 'model' => App\Models\User::class, 6 ], 7 8?> 9

試したこと

➀config\auth.phpのprovidersの
App\User::class, → App\Models\User::class,
に変更しました。
検索してもこの変更以外出てこないです。

➁クラス名変更していないのですが
composer dump-autoload
を一応実行しました。

すいませんが、ご教授よろしくお願い致します。

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

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

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

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

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

退会済みユーザー

退会済みユーザー

2019/12/16 03:40

namespace が変われば別クラスですよ
jiro-

2019/12/17 09:47

ご返信ありがとうございます。 アドバイス頂いているのに返事が遅くなりもうしわけありません。 ご指摘の通りnamespaceが合ってなかったようです。 無事解決できました。ありがとうございました!
guest

回答1

0

ベストアンサー

投稿2019/12/16 03:17

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

jiro-

2019/12/17 09:49

ご回答ありがとうございます。 ご指摘頂いたサイトと同様階層もズレてしまっていました。 無事解決できました。ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問