1. Lỗi khi Migrate data
Khi thực hiện lệnh:
php artisan migrate
Báo lỗi:
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Illuminate\Database\QueryException
nique`(`email`))
nique`(`email`))
at D:\xampp\htdocs\vue-laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:678
674▕ // If an exception occurs when attempting to run a query, we'll format the error
675▕ // message to include the bindings with SQL, which will make this exception a
676▕ // lot more helpful to the developer instead of just the database's errors.
677▕ catch (Exception $e) {
➜ 678▕ throw new QueryException(
679▕ $query, $this->prepareBindings($bindings), $e
680▕ );
681▕ }
682▕
1 D:\xampp\htdocs\vue-laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:471
PDOException::("SQLSTATE[HY000]: General error: 1709 Index column size too large. The maximum column size is 767 bytes.")
2 D:\xampp\htdocs\vue-laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:471
PDOStatement::execute()
Cách khắc phục:
Vào đường dẫn: App\Providers\AppServiceProvider.php
Thêm:
use Illuminate\Support\Facades\Schema;
Trong hàm boot() thêm hàm sau:
Schema::defaultStringLength(191);
2. Lỗi “npm ERR! code ELIFECYCLE”
Error: You are using an unsupported version of Node. Please update to at least Node v12.14
at assertSupportedNodeVersion (D:\xampp\htdocs\vue-laravel\node_modules\laravel-mix\src\Engine.js:6:15)
at executeScript (D:\xampp\htdocs\vue-laravel\node_modules\laravel-mix\bin\cli.js:61:5)
at Command.program.command.description.option.option.action (D:\xampp\htdocs\vue-laravel\node_modules\laravel-mix\bin\cli.js:39:13)
at Command.listener [as _actionHandler] (D:\xampp\htdocs\vue-laravel\node_modules\commander\index.js:922:31)
at Command._parseCommand (D:\xampp\htdocs\vue-laravel\node_modules\commander\index.js:1503:14)
at Command._dispatchSubcommand (D:\xampp\htdocs\vue-laravel\node_modules\commander\index.js:1443:18)
at Command._parseCommand (D:\xampp\htdocs\vue-laravel\node_modules\commander\index.js:1460:12)
at Command.parse (D:\xampp\htdocs\vue-laravel\node_modules\commander\index.js:1292:10)
at Command.parseAsync (D:\xampp\htdocs\vue-laravel\node_modules\commander\index.js:1318:10)
at run (D:\xampp\htdocs\vue-laravel\node_modules\laravel-mix\bin\cli.js:50:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ watch: `mix watch`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\THU\AppData\Roaming\npm-cache\_logs\2021-04-13T05_03_17_044Z-debug.log
Với lỗi này, bạn thực hiện cài lại npm theo cách sau:
Cách 1: Cài lại npm theo cách sau:
- Xóa cache npm
npm cache clean --force
2. Xóa thưc node_modules
và package-lock.json
trong thư mục dự án
rm -rf node_modules package-lock.json
3. Tiến hành cài đặt lại npm
npm install
4. Chạy lại dự án bằng lệnh npm start
hoặc npm run dev
Cách 2. cài lại nodejs từ trang chủ
Url: https://nodejs.org/en/download/
Tải file cài đặt mới nhất về máy tính và nhấn next tới khi kết thúc,
sau đó: thêm ;C:\Program Files\nodejs\ vào đường dẫn sau.
control panel –>System and Security–> System –> Advanced System Security–> Environment Variables
3. Lỗi Target class controller does not exist – Laravel 8
Illuminate\Contracts\Container\BindingResolutionException
Target class [ContactController] does not exist.
Lỗi này do cấu hình Route:
Route::prefix('api')->group(function(){
// Get contact
Route::get('/getContacts', 'ContactController@getContacts');
});
Khắc phục:
Cách 1. Cấu hình lại route
thêm
App\Http\Controllers\
Vào
Route::prefix('api')->group(function(){
// Get contact
Route::get('/getContacts', 'App\Http\Controllers\ContactController@getContacts');
});
Cách 2. Cấu hình lại file RouteServiceProvider.php
Vào app > Providers > RouteServiceProvider.php
thay
protected $namespace = null;
Thành
protected $namespace = 'App\Http\Controllers';
Như hình sau: