LoginSignup
0
0

More than 3 years have passed since last update.

Laravel エラー辞書(自分用)

Last updated at Posted at 2021-06-10

PHP Error: Class "Post" not found in Psy Shell code on line 1

PHPのエラーだが、対話型シェル(oho artisan tinker)でモデルを触ろうと思っても、反応しない

解決策:$ composer dump-autoload

これに関しては、コード一発で解決する。
詳しくないが、Vender配下の当該ファイルにファイルパスが自動的に追加されるらしい。


composer dump-autoload

Class "App\Http\Controllers\DB" not found

絶対にあるはずのが、claaが見つからないケース

解決策:名前空間の追記

vnder内のLaravelのDBクラスまでの、名前空間を追記してやる。
use Illuminate\Support\Facades\DB;

PostController.php



<?php

namespace App\Http\Controllers;

use App\Models\Post;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; # ← コレ

Target class [PostController] does not exist.

コントローラが見つからない。

解決策①:ルートのpassを確認

web.phpのnamespaceを完全にに指定する。
App\Http\Controllers\を追加して完全に指定

web.php

Route::get('/home', 'HomeController@index')->name('home');

web.php

Route::get('/home', 'App\Http\Controllers\HomeController@index')->name('home');

Illuminate\Database\QueryException

Laravelの.envに記載されているDB情報のMYSQLに接続できない。


   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:692
    688▕         // If an exception occurs when attempting to run a query, we'll format the error
    689▕         // message to include the bindings with SQL, which will make this exception a
    690▕         // lot more helpful to the developer instead of just the database's errors.
    691▕         catch (Exception $e) {
  ➜ 692▕             throw new QueryException(
    693▕                 $query, $this->prepareBindings($bindings), $e
    694▕             );
    695▕         }
    696▕ 

解決策①:.envの記載内容を確認する。

解決策②:MYSQLでデータベースを作成する


# mysql serverを立てる
mysql.server start

# rootユーザーにログインする 
mysql -uroot  

-- rootで、userを追加する (name:"ryo", password:"0320")
create user 'ryo' identified by '0320';

-- rootはフルアクセスなので、ryoにデータベースを作成する権限を与える。
grant all on ryo. * to 'ryo';

-- 一旦rootから抜ける。
exit;

# ryoユーザーにログインする
mysql -uryo -p0320;

-- データベースを作成する
create database ryo;

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0