nhiepphong bắt đầu chủ đề từ 6 năm trước

@nhiepphong ·


Laravel hiện đang là framework php tốt nhất, đứng TOP 1 trong 3 năm liền trên bảng xếp hạng các Framework tốt nhất. Số lượng lập trình viên sử dụng Laravel ngày càng tăng lên, sau đây mình xin tổng hợp một số lỗi mà anh em thường gặp khi làm việc với Laravel Framework.

1

RuntimeException in EncryptionServiceProvider.php line 29:                      
No supported encrypter found. The cipher and / or key length are invalid                        
in EncryptionServiceProvider.php line 29                        
at EncryptionServiceProvider->Illuminate\Encryption\{closure}(object(Application), array()) in Container.php line 733                       
at Container->build(object(Closure), array()) in Container.php line 626                     
at Container->make('encrypter', array()) in Application.php line 674                        
at Application->make('Illuminate\Contracts\Encryption\Encrypter') in Container.php line 837                     
at Container->resolveClass(object(ReflectionParameter)) in Container.php line 800                       
at Container->getDependencies(array(object(ReflectionParameter)), array()) in Container.php line 771                        
at Container->build('SahraSalon\Http\Middleware\EncryptCookies', array()) in Container.php line 626                     
at Container->make('SahraSalon\Http\Middleware\EncryptCookies', array()) in Application.php line 674                        
.....

Cách giải quyết :

chạy command php artisan key:generate

2

Whoops, looks like something went wrong
Warning: require(D:\xampp\htdocs\Laravel-5-Bootstrap-3-Starter-Site-master\bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in D:\xampp\htdocs\Laravel-5-Bootstrap-3-Starter-Site-master\bootstrap\autoload.php on line 17

Fatal error: require(): Failed opening required 'D:\xampp\htdocs\Laravel-5-Bootstrap-3-Starter-Site-master\bootstrap/../vendor/autoload.php' (include_path='D:\xampp\php\PEAR') in D:\xampp\htdocs\Laravel-5-Bootstrap-3-Starter-Site-master\bootstrap\autoload.php on line 17

Cách giải quyết :

kiểm đã có file .env trong thư mục source gốc chưa, có thể chạy lệnh php artisan key:generate

3

Unexpected Exception: SQLSTATE[HY000] [1045] Access denied for user ****@'localhost' (using password: YES)

Cách giải quyết :

kiểm tra lại lại thông tin cấu hình kết nối tớ Database trong file .env hoặc trong config/database.php

DB_HOST=localhost
DB_DATABASE=nn
DB_USERNAME=root
DB_PASSWORD=null
DB_LOGQUERY=true

4

 [ReflectionException]
 Class UsersTableSeeder does not exist

Cách giải quyết :

Bạn mới tạo 1 class , check đi check lại thấy đúng đường dẫn, đúng tên, đúng đuôi file, mà vẫn báo lỗi này thì câu lệnh sau có thể giúp bạn composer dump-autoload

5

TokenMismatchException in VerifyCsrfToken.php line 68:

Cách giải quyết :

Chưa có token trong form khi submit, thêm code sau vào <form>...</form>

{{ csrf_field() }}

Chưa có token khi gửi ajax jquery , cài đặt axjax header:

$.ajaxSetup({
     headers: {
         'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
     }
});

6

NotFoundHttpException in RouteCollection.php

Cách giải quyết :

Lỗi thư mục không có quyền hãy set lại quyền

sudo chmod -R 777 storage
sudo chmod -R 777 bootstrap/cache

7

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Cách giải quyết :

sửa trong file AppServiceProvider.php

use Illuminate\Support\Facades\Schema;
.....
public function boot()
{
Schema::defaultStringLength(191);
}

Kết

Trong quá trình làm việc với Laravel Framework anh em còn hay gặp những lỗi nào, Hãy comment phía dưới nhé !

Viết câu trả lời

Drop Images

1 Bình luận

hcthang avatar

tôi đang bị lỗi số 7 mặc dù trước đó tôi cấu hình nó là 191 rồi. Còn nguyên nhân nào nữa bạn nhỉ