Xác thực Laravel tồn tại hai cột

Laravel cung cấp một số cách tiếp cận khác nhau để xác thực dữ liệu đến của ứng dụng của bạn. Cách phổ biến nhất là sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 có sẵn trên tất cả các yêu cầu HTTP đến. Tuy nhiên, chúng tôi cũng sẽ thảo luận về các cách tiếp cận khác để xác nhận

Laravel bao gồm nhiều quy tắc xác thực thuận tiện mà bạn có thể áp dụng cho dữ liệu, thậm chí cung cấp khả năng xác thực nếu các giá trị là duy nhất trong một bảng cơ sở dữ liệu nhất định. Chúng tôi sẽ trình bày chi tiết từng quy tắc xác thực này để bạn quen thuộc với tất cả các tính năng xác thực của Laravel

Bắt đầu nhanh xác thực

Để tìm hiểu về các tính năng xác thực mạnh mẽ của Laravel, hãy xem một ví dụ hoàn chỉnh về xác thực biểu mẫu và hiển thị lại thông báo lỗi cho người dùng. Bằng cách đọc phần tổng quan cấp cao này, bạn sẽ có thể hiểu rõ hơn về cách xác thực dữ liệu yêu cầu gửi đến bằng cách sử dụng Laravel

Xác định các tuyến đường

Trước tiên, giả sử chúng ta có các tuyến sau được xác định trong tệp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

22 của mình

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

Lộ trình

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

23 sẽ hiển thị một biểu mẫu để người dùng tạo một bài đăng blog mới, trong khi lộ trình

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

24 sẽ lưu trữ bài đăng blog mới trong cơ sở dữ liệu

Tạo bộ điều khiển

Tiếp theo, chúng ta hãy xem một bộ điều khiển đơn giản xử lý các yêu cầu đến các tuyến này. Bây giờ chúng ta sẽ để trống phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

25

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

Viết logic xác thực

Bây giờ chúng ta đã sẵn sàng để điền logic vào phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

25 của mình để xác thực bài đăng blog mới. Để làm điều này, chúng ta sẽ sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 được cung cấp bởi đối tượng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

28. Nếu các quy tắc xác thực vượt qua, mã của bạn sẽ tiếp tục thực thi bình thường;

Nếu xác thực không thành công trong yêu cầu HTTP truyền thống, phản hồi chuyển hướng tới URL trước đó sẽ được tạo. Nếu yêu cầu đến là yêu cầu XHR, a sẽ được trả lại

Để hiểu rõ hơn về phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21, hãy quay lại phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

25

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

3

Như bạn có thể thấy, các quy tắc xác thực được chuyển vào phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21. Đừng lo lắng - tất cả các quy tắc xác thực có sẵn đều. Một lần nữa, nếu xác thực không thành công, phản hồi thích hợp sẽ tự động được tạo. Nếu vượt qua xác thực, bộ điều khiển của chúng tôi sẽ tiếp tục thực hiện bình thường

Ngoài ra, các quy tắc xác thực có thể được chỉ định dưới dạng các mảng quy tắc thay vì một chuỗi phân cách

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

33

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

6

Ngoài ra, bạn có thể sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

34 để xác thực yêu cầu và lưu trữ bất kỳ thông báo lỗi nào trong một

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

8

Dừng khi xác nhận lần đầu không thành công

Đôi khi, bạn có thể muốn ngừng chạy các quy tắc xác thực trên một thuộc tính sau lần xác thực đầu tiên không thành công. Để làm như vậy, hãy gán quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

35 cho thuộc tính

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

0

Trong ví dụ này, nếu quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

36 trên thuộc tính

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

37 không thành công, quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

38 sẽ không được chọn. Các quy tắc sẽ được xác thực theo thứ tự chúng được chỉ định

Lưu ý về các thuộc tính lồng nhau

Nếu yêu cầu HTTP đến chứa dữ liệu trường "lồng nhau", bạn có thể chỉ định các trường này trong quy tắc xác thực của mình bằng cú pháp "dấu chấm"

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

4

Mặt khác, nếu tên trường của bạn chứa dấu chấm bằng chữ, bạn có thể ngăn điều này một cách rõ ràng để không bị hiểu là cú pháp "dấu chấm" bằng cách thoát dấu chấm bằng dấu gạch chéo ngược

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

5

Hiển thị lỗi xác thực

Vì vậy, điều gì sẽ xảy ra nếu các trường yêu cầu đến không vượt qua các quy tắc xác thực đã cho? . Ngoài ra, tất cả các lỗi xác thực và sẽ tự động được

Một biến

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

39 được chia sẻ với tất cả các chế độ xem ứng dụng của bạn bởi phần mềm trung gian

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

40, được cung cấp bởi nhóm phần mềm trung gian

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

41. Khi phần mềm trung gian này được áp dụng, một biến

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

39 sẽ luôn có sẵn trong chế độ xem của bạn, cho phép bạn giả định một cách thuận tiện rằng biến

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

39 luôn được xác định và có thể được sử dụng một cách an toàn. Biến

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

39 sẽ là một thể hiện của

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

45. Để biết thêm thông tin về cách làm việc với đối tượng này,

Vì vậy, trong ví dụ của chúng tôi, người dùng sẽ được chuyển hướng đến phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

46 của bộ điều khiển của chúng tôi khi xác thực không thành công, cho phép chúng tôi hiển thị thông báo lỗi trong chế độ xem

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

4

Tùy chỉnh Thông báo Lỗi

Mỗi quy tắc xác thực tích hợp của Laravel đều có một thông báo lỗi nằm trong tệp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

47 của ứng dụng của bạn. Trong tệp này, bạn sẽ tìm thấy mục dịch cho từng quy tắc xác thực. Bạn có thể tự do thay đổi hoặc sửa đổi các thông báo này dựa trên nhu cầu của ứng dụng của bạn

Ngoài ra, bạn có thể sao chép tệp này sang thư mục ngôn ngữ dịch thuật khác để dịch các thông báo cho ngôn ngữ của ứng dụng của bạn. Để tìm hiểu thêm về bản địa hóa Laravel, hãy xem tài liệu bản địa hóa đầy đủ

Yêu cầu & Xác thực XHR

Trong ví dụ này, chúng tôi đã sử dụng một biểu mẫu truyền thống để gửi dữ liệu đến ứng dụng. Tuy nhiên, nhiều ứng dụng nhận được yêu cầu XHR từ giao diện người dùng được hỗ trợ bởi JavaScript. Khi sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 trong một yêu cầu XHR, Laravel sẽ không tạo phản hồi chuyển hướng. Thay vào đó, Laravel tạo ra một. Phản hồi JSON này sẽ được gửi cùng với mã trạng thái HTTP 422

Chỉ thị

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

49

Bạn có thể sử dụng chỉ thị

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

49 Blade để nhanh chóng xác định xem có tồn tại thông báo lỗi xác thực cho một thuộc tính nhất định hay không. Trong một chỉ thị

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

49, bạn có thể lặp lại biến

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

52 để hiển thị thông báo lỗi

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

1

Nếu bạn đang sử dụng , bạn có thể chuyển tên của túi lỗi làm đối số thứ hai cho chỉ thị

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

49

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

0

Hình thức tái tạo

Khi Laravel tạo phản hồi chuyển hướng do lỗi xác thực, khung sẽ tự động. Điều này được thực hiện để bạn có thể truy cập thông tin đầu vào một cách thuận tiện trong yêu cầu tiếp theo và điền lại biểu mẫu mà người dùng đã cố gắng gửi

Để truy xuất đầu vào được flash từ yêu cầu trước đó, hãy gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

54 trên phiên bản của

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

28. Phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

54 sẽ lấy dữ liệu đầu vào được flash trước đó từ phiên

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

1

Laravel cũng cung cấp một trình trợ giúp toàn cầu

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

54. Nếu bạn đang hiển thị đầu vào cũ trong mẫu Blade, sẽ thuận tiện hơn khi sử dụng trình trợ giúp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

54 để điền lại biểu mẫu. Nếu không có đầu vào cũ nào tồn tại cho trường đã cho, thì

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59 sẽ được trả về

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

0

Lưu ý về các trường tùy chọn

Theo mặc định, Laravel bao gồm phần mềm trung gian

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

60 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

61 trong ngăn xếp phần mềm trung gian toàn cầu của ứng dụng của bạn. Các phần mềm trung gian này được liệt kê trong ngăn xếp theo lớp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

62. Do đó, bạn sẽ thường cần đánh dấu các trường yêu cầu "tùy chọn" của mình là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

63 nếu bạn không muốn trình xác thực coi các giá trị

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59 là không hợp lệ. Ví dụ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

3

Trong ví dụ này, chúng tôi chỉ định rằng trường

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

65 có thể là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59 hoặc biểu diễn ngày hợp lệ. Nếu công cụ sửa đổi

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

63 không được thêm vào định nghĩa quy tắc, trình xác thực sẽ coi

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59 là một ngày không hợp lệ

Định dạng phản hồi lỗi xác thực

Khi ứng dụng của bạn đưa ra một ngoại lệ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

29 và yêu cầu HTTP đến đang mong đợi một phản hồi JSON, Laravel sẽ tự động định dạng các thông báo lỗi cho bạn và trả về một phản hồi HTTP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

70

Dưới đây, bạn có thể xem lại một ví dụ về định dạng phản hồi JSON cho các lỗi xác thực. Lưu ý rằng các khóa lỗi lồng nhau được làm phẳng thành định dạng ký hiệu "dấu chấm"

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

4

Xác nhận yêu cầu biểu mẫu

Tạo yêu cầu biểu mẫu

Đối với các tình huống xác thực phức tạp hơn, bạn có thể muốn tạo một "yêu cầu biểu mẫu". Yêu cầu biểu mẫu là các lớp yêu cầu tùy chỉnh đóng gói logic xác thực và ủy quyền của riêng chúng. Để tạo một lớp yêu cầu biểu mẫu, bạn có thể sử dụng lệnh

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

71 Artisan CLI

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

5

Lớp yêu cầu biểu mẫu được tạo sẽ được đặt trong thư mục

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

72. Nếu thư mục này không tồn tại, nó sẽ được tạo khi bạn chạy lệnh

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

71. Mỗi yêu cầu biểu mẫu được tạo bởi Laravel có hai phương thức.

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

74 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

75

Như bạn có thể đoán, phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

74 chịu trách nhiệm xác định xem người dùng hiện được xác thực có thể thực hiện hành động được yêu cầu thể hiện hay không, trong khi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

75 trả về các quy tắc xác thực sẽ áp dụng cho dữ liệu của yêu cầu

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

6

Lưu ý
Bạn có thể nhập gợi ý bất kỳ phụ thuộc nào bạn yêu cầu trong chữ ký của phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

75. Chúng sẽ tự động được giải quyết thông qua Laravel service container.

Vì vậy, các quy tắc xác nhận được đánh giá như thế nào? . Yêu cầu biểu mẫu đến được xác thực trước khi phương thức bộ điều khiển được gọi, nghĩa là bạn không cần phải làm lộn xộn bộ điều khiển của mình với bất kỳ logic xác thực nào

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

7

Nếu xác thực không thành công, phản hồi chuyển hướng sẽ được tạo để đưa người dùng trở lại vị trí trước đó của họ. Các lỗi cũng sẽ được flash vào phiên để chúng có sẵn để hiển thị. Nếu yêu cầu là yêu cầu XHR, phản hồi HTTP có mã trạng thái 422 sẽ được trả lại cho người dùng bao gồm

Thêm After Hook vào Form Request

Nếu bạn muốn thêm móc xác thực "sau" vào yêu cầu biểu mẫu, bạn có thể sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

79. Phương thức này nhận được trình xác thực được xây dựng đầy đủ, cho phép bạn gọi bất kỳ phương thức nào của nó trước khi các quy tắc xác thực thực sự được đánh giá

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

8

Dừng trên thuộc tính lỗi xác thực đầu tiên

Bằng cách thêm thuộc tính

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

80 vào lớp yêu cầu của bạn, bạn có thể thông báo cho trình xác thực rằng nó sẽ ngừng xác thực tất cả các thuộc tính sau khi xảy ra lỗi xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

9

Tùy chỉnh vị trí chuyển hướng

Như đã thảo luận trước đó, phản hồi chuyển hướng sẽ được tạo để gửi người dùng trở lại vị trí trước đó của họ khi xác thực yêu cầu biểu mẫu không thành công. Tuy nhiên, bạn có thể tự do tùy chỉnh hành vi này. Để làm như vậy, hãy xác định thuộc tính

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

81 theo yêu cầu biểu mẫu của bạn

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

30

Hoặc, nếu bạn muốn chuyển hướng người dùng đến một tuyến đường đã đặt tên, thay vào đó, bạn có thể xác định thuộc tính

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

82

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

31

Yêu cầu biểu mẫu ủy quyền

Lớp yêu cầu biểu mẫu cũng chứa một phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

74. Trong phương pháp này, bạn có thể xác định xem người dùng được xác thực có thực sự có quyền cập nhật một tài nguyên nhất định hay không. Ví dụ: bạn có thể xác định xem người dùng có thực sự sở hữu nhận xét blog mà họ đang cố cập nhật hay không. Rất có thể, bạn sẽ tương tác với các cổng và chính sách ủy quyền của mình trong phương pháp này

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

32

Vì tất cả các yêu cầu biểu mẫu mở rộng lớp yêu cầu Laravel cơ sở, chúng tôi có thể sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

84 để truy cập người dùng hiện được xác thực. Ngoài ra, hãy lưu ý cuộc gọi đến phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

85 trong ví dụ trên. Phương thức này cấp cho bạn quyền truy cập vào các tham số URI được xác định trên tuyến đang được gọi, chẳng hạn như tham số

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

86 trong ví dụ bên dưới

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

33

Do đó, nếu ứng dụng của bạn đang tận dụng lợi thế của , mã của bạn có thể được làm ngắn gọn hơn nữa bằng cách truy cập vào mô hình đã giải quyết dưới dạng thuộc tính của yêu cầu

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

34

Nếu phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

74 trả về

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

88, phản hồi HTTP có mã trạng thái 403 sẽ tự động được trả về và phương thức điều khiển của bạn sẽ không thực thi

Nếu bạn định xử lý logic ủy quyền cho yêu cầu trong một phần khác của ứng dụng, bạn có thể chỉ cần trả về

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

89 từ phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

74

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

35

Lưu ý
Bạn có thể nhập gợi ý bất kỳ phụ thuộc nào bạn cần trong chữ ký của phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

74. Chúng sẽ tự động được giải quyết thông qua Laravel service container.

Tùy chỉnh Thông báo Lỗi

Bạn có thể tùy chỉnh các thông báo lỗi được sử dụng bởi yêu cầu biểu mẫu bằng cách ghi đè phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

92. Phương thức này sẽ trả về một mảng các cặp thuộc tính/quy tắc và các thông báo lỗi tương ứng của chúng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

36

Tùy chỉnh các thuộc tính xác thực

Nhiều thông báo lỗi quy tắc xác thực tích hợp sẵn của Laravel chứa trình giữ chỗ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

93. Nếu bạn muốn thay thế trình giữ chỗ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

93 của thông báo xác thực bằng tên thuộc tính tùy chỉnh, bạn có thể chỉ định tên tùy chỉnh bằng cách ghi đè phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

95. Phương thức này sẽ trả về một mảng các cặp thuộc tính/tên

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

37

Chuẩn bị đầu vào để xác thực

Nếu bạn cần chuẩn bị hoặc làm sạch bất kỳ dữ liệu nào từ yêu cầu trước khi áp dụng các quy tắc xác thực của mình, bạn có thể sử dụng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

96

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

38

Tạo thủ công Trình xác thực

Nếu bạn không muốn sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 theo yêu cầu, bạn có thể tạo phiên bản trình xác thực theo cách thủ công bằng cách sử dụng mặt tiền

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

98. Phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

99 trên mặt tiền tạo một phiên bản trình xác thực mới

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

39

Đối số đầu tiên được truyền cho phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

99 là dữ liệu đang được xác thực. Đối số thứ hai là một mảng các quy tắc xác thực sẽ được áp dụng cho dữ liệu

Sau khi xác định xem xác thực yêu cầu có thất bại hay không, bạn có thể sử dụng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

301 để flash thông báo lỗi vào phiên. Khi sử dụng phương pháp này, biến

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

39 sẽ tự động được chia sẻ với chế độ xem của bạn sau khi chuyển hướng, cho phép bạn dễ dàng hiển thị lại cho người dùng. Phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

301 chấp nhận trình xác thực,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

304 hoặc PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

305

Dừng khi xác nhận lần đầu không thành công

Phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

80 sẽ thông báo cho trình xác thực rằng nó sẽ ngừng xác thực tất cả các thuộc tính sau khi xảy ra lỗi xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

60

Chuyển hướng tự động

Nếu bạn muốn tạo phiên bản trình xác thực theo cách thủ công nhưng vẫn tận dụng lợi thế của chuyển hướng tự động do phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 của yêu cầu HTTP cung cấp, bạn có thể gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 trên phiên bản trình xác thực hiện có. Nếu xác thực không thành công, người dùng sẽ tự động được chuyển hướng hoặc trong trường hợp yêu cầu XHR, một

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

61

Bạn có thể sử dụng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

34 để lưu trữ các thông báo lỗi trong một if quá trình xác thực không thành công

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

62

Túi lỗi được đặt tên

Nếu bạn có nhiều biểu mẫu trên một trang, bạn có thể đặt tên cho

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

304 chứa các lỗi xác thực, cho phép bạn truy xuất các thông báo lỗi cho một biểu mẫu cụ thể. Để đạt được điều này, hãy chuyển một tên làm đối số thứ hai cho

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

301

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

63

Sau đó, bạn có thể truy cập phiên bản

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

304 có tên từ biến

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

39

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

64

Tùy chỉnh Thông báo Lỗi

Nếu cần, bạn có thể cung cấp thông báo lỗi tùy chỉnh mà phiên bản trình xác thực nên sử dụng thay vì thông báo lỗi mặc định do Laravel cung cấp. Có một số cách để chỉ định thông báo tùy chỉnh. Trước tiên, bạn có thể chuyển các thông báo tùy chỉnh làm đối số thứ ba cho phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

314

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

65

Trong ví dụ này, trình giữ chỗ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

93 sẽ được thay thế bằng tên thực của trường được xác thực. Bạn cũng có thể sử dụng các trình giữ chỗ khác trong thông báo xác thực. Ví dụ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

66

Chỉ định một thông báo tùy chỉnh cho một thuộc tính nhất định

Đôi khi bạn có thể muốn chỉ định một thông báo lỗi tùy chỉnh chỉ cho một thuộc tính cụ thể. Bạn có thể làm như vậy bằng cách sử dụng ký hiệu "dấu chấm". Chỉ định tên của thuộc tính trước, sau đó là quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

67

Chỉ định giá trị thuộc tính tùy chỉnh

Nhiều thông báo lỗi tích hợp của Laravel bao gồm một trình giữ chỗ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

93 được thay thế bằng tên của trường hoặc thuộc tính được xác thực. Để tùy chỉnh các giá trị được sử dụng để thay thế các trình giữ chỗ này cho các trường cụ thể, bạn có thể chuyển một mảng các thuộc tính tùy chỉnh làm đối số thứ tư cho phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

314

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

68

Móc sau khi xác thực

Bạn cũng có thể đính kèm các cuộc gọi lại để chạy sau khi xác thực hoàn tất. Điều này cho phép bạn dễ dàng thực hiện xác thực thêm và thậm chí thêm nhiều thông báo lỗi hơn vào bộ sưu tập thông báo. Để bắt đầu, hãy gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

318 trên phiên bản trình xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

69

Làm việc với đầu vào đã xác thực

Sau khi xác thực dữ liệu yêu cầu đến bằng yêu cầu biểu mẫu hoặc phiên bản trình xác thực được tạo thủ công, bạn có thể muốn truy xuất dữ liệu yêu cầu đến thực sự đã trải qua quá trình xác thực. Điều này có thể được thực hiện theo nhiều cách. Đầu tiên, bạn có thể gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

319 trên một yêu cầu biểu mẫu hoặc phiên bản trình xác thực. Phương thức này trả về một mảng dữ liệu đã được xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

80

Ngoài ra, bạn có thể gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

320 trên yêu cầu biểu mẫu hoặc phiên bản trình xác thực. Phương thức này trả về một thể hiện của

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

321. Đối tượng này hiển thị các phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

322,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

323 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

324 để truy xuất một tập hợp con của dữ liệu đã xác thực hoặc toàn bộ mảng dữ liệu đã xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

81

Ngoài ra, phiên bản

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

321 có thể được lặp lại và truy cập giống như một mảng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

82

Nếu bạn muốn thêm các trường bổ sung vào dữ liệu đã xác thực, bạn có thể gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

326

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

83

Nếu bạn muốn truy xuất dữ liệu đã được xác thực dưới dạng một phiên bản bộ sưu tập, bạn có thể gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

327

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

84

Làm việc với thông báo lỗi

Sau khi gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

328 trên phiên bản

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

98, bạn sẽ nhận được phiên bản

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

45, phiên bản này có nhiều phương thức thuận tiện để làm việc với các thông báo lỗi. Biến

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

39 được tự động cung cấp cho tất cả các chế độ xem cũng là một thể hiện của lớp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

304

Truy xuất thông báo lỗi đầu tiên cho một trường

Để truy xuất thông báo lỗi đầu tiên cho một trường nhất định, hãy sử dụng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

333

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

85

Truy xuất tất cả các thông báo lỗi cho một trường

Nếu bạn cần truy xuất một mảng gồm tất cả các thông báo cho một trường nhất định, hãy sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

334

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

86

Nếu bạn đang xác thực trường dạng mảng, bạn có thể truy xuất tất cả thông báo cho từng phần tử mảng bằng cách sử dụng ký tự

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

335

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

87

Truy xuất tất cả các thông báo lỗi cho tất cả các trường

Để truy xuất một mảng gồm tất cả các thông báo cho tất cả các trường, hãy sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

324

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

88

Xác định xem có tồn tại thông báo cho một trường hay không

Phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

337 có thể được sử dụng để xác định xem có bất kỳ thông báo lỗi nào tồn tại đối với một trường nhất định hay không

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

89

Chỉ định tin nhắn tùy chỉnh trong tệp ngôn ngữ

Mỗi quy tắc xác thực tích hợp của Laravel đều có một thông báo lỗi nằm trong tệp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

47 của ứng dụng của bạn. Trong tệp này, bạn sẽ tìm thấy mục dịch cho từng quy tắc xác thực. Bạn có thể tự do thay đổi hoặc sửa đổi các thông báo này dựa trên nhu cầu của ứng dụng của bạn

Ngoài ra, bạn có thể sao chép tệp này sang thư mục ngôn ngữ dịch thuật khác để dịch các thông báo cho ngôn ngữ của ứng dụng của bạn. Để tìm hiểu thêm về bản địa hóa Laravel, hãy xem tài liệu bản địa hóa đầy đủ

Thông báo tùy chỉnh cho các thuộc tính cụ thể

Bạn có thể tùy chỉnh các thông báo lỗi được sử dụng cho các kết hợp quy tắc và thuộc tính được chỉ định trong các tệp ngôn ngữ xác thực của ứng dụng của bạn. Để làm như vậy, hãy thêm các tùy chỉnh tin nhắn của bạn vào mảng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

339 trong tệp ngôn ngữ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

340 của ứng dụng của bạn

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

00

Chỉ định thuộc tính trong tệp ngôn ngữ

Nhiều thông báo lỗi tích hợp của Laravel bao gồm một trình giữ chỗ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

93 được thay thế bằng tên của trường hoặc thuộc tính được xác thực. Nếu bạn muốn thay thế phần

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

93 của thông báo xác thực bằng một giá trị tùy chỉnh, bạn có thể chỉ định tên thuộc tính tùy chỉnh trong mảng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

95 của tệp ngôn ngữ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

340 của mình

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

01

Chỉ định giá trị trong tệp ngôn ngữ

Một số thông báo lỗi quy tắc xác thực tích hợp của Laravel chứa trình giữ chỗ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

345 được thay thế bằng giá trị hiện tại của thuộc tính yêu cầu. Tuy nhiên, đôi khi bạn có thể cần thay thế phần

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

345 trong thông báo xác thực của mình bằng một biểu thị tùy chỉnh của giá trị. Ví dụ: hãy xem xét quy tắc sau đây chỉ định rằng số thẻ tín dụng là bắt buộc nếu

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

347 có giá trị là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

348

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

02

Nếu quy tắc xác thực này không thành công, nó sẽ tạo ra thông báo lỗi sau

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

03

Thay vì hiển thị

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

348 dưới dạng giá trị loại thanh toán, bạn có thể chỉ định cách biểu diễn giá trị thân thiện với người dùng hơn trong tệp ngôn ngữ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

340 của mình bằng cách xác định một mảng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

351

Sau khi xác định giá trị này, quy tắc xác thực sẽ tạo ra thông báo lỗi sau

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

04

Quy tắc xác thực có sẵn

Dưới đây là danh sách tất cả các quy tắc xác thực có sẵn và chức năng của chúng

Đã được chấp nhận

Trường được xác thực phải là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

352,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

353,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

354 hoặc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

89. Điều này hữu ích để xác thực việc chấp nhận "Điều khoản dịch vụ" hoặc các trường tương tự

accept_if. trường khác, giá trị,

Trường đang được xác thực phải là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

352,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

353,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

354 hoặc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

89 nếu một trường khác đang được xác thực bằng một giá trị đã chỉ định. Điều này hữu ích để xác thực việc chấp nhận "Điều khoản dịch vụ" hoặc các trường tương tự

active_url

Trường được xác thực phải có bản ghi A hoặc AAAA hợp lệ theo chức năng PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

360. Tên máy chủ của URL đã cung cấp được trích xuất bằng cách sử dụng hàm PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

361 trước khi được chuyển đến

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

360

sau đó. ngày tháng

Trường được xác thực phải là một giá trị sau một ngày nhất định. Ngày sẽ được chuyển vào hàm ________ 1363 PHP để được chuyển đổi thành phiên bản ________ 1364 hợp lệ

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

05

Thay vì chuyển một chuỗi ngày để được đánh giá bởi

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

363, bạn có thể chỉ định một trường khác để so sánh với ngày

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

06

after_or_equal. ngày tháng

Trường được xác thực phải là một giá trị sau hoặc bằng ngày đã cho. Để biết thêm thông tin, hãy xem quy tắc

chữ cái

Trường được xác thực phải hoàn toàn là ký tự chữ cái

alpha_dash

Trường được xác thực có thể có các ký tự chữ và số, cũng như dấu gạch ngang và dấu gạch dưới

alpha_num

Trường được xác thực phải hoàn toàn là ký tự chữ và số

mảng

Trường được xác thực phải là PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

305

Khi các giá trị bổ sung được cung cấp cho quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

305, mỗi khóa trong mảng đầu vào phải có trong danh sách các giá trị được cung cấp cho quy tắc. Trong ví dụ sau, khóa

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

368 trong mảng đầu vào không hợp lệ vì nó không có trong danh sách các giá trị được cung cấp cho quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

305

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

07

Nói chung, bạn phải luôn chỉ định các khóa mảng được phép có trong mảng của mình

ascii

Trường được xác thực phải hoàn toàn là các ký tự ASCII 7 bit

bảo lãnh

Ngừng chạy các quy tắc xác thực cho trường sau lần xác thực đầu tiên không thành công

Mặc dù quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

35 sẽ chỉ dừng xác thực một trường cụ thể khi nó gặp lỗi xác thực, nhưng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

80 sẽ thông báo cho trình xác thực rằng nó sẽ ngừng xác thực tất cả các thuộc tính sau khi xảy ra lỗi xác thực.

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

60

trước. ngày tháng

Trường được xác thực phải là một giá trị trước ngày đã cho. Các ngày sẽ được chuyển vào hàm PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

363 để được chuyển đổi thành một phiên bản

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

364 hợp lệ. Ngoài ra, giống như quy tắc, tên của một trường khác đang được xác thực có thể được cung cấp dưới dạng giá trị của

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

375

before_or_equal. ngày tháng

Trường được xác thực phải là một giá trị trước hoặc bằng ngày đã cho. Các ngày sẽ được chuyển vào hàm PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

363 để được chuyển đổi thành một phiên bản

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

364 hợp lệ. Ngoài ra, giống như quy tắc, tên của một trường khác đang được xác thực có thể được cung cấp dưới dạng giá trị của

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

375

ở giữa. nhỏ nhất lớn nhất

Trường được xác thực phải có kích thước nằm trong khoảng từ tối thiểu đến tối đa đã cho [đã bao gồm]. Các chuỗi, số, mảng và tệp được đánh giá theo cùng một kiểu với quy tắc

boolean

Trường được xác thực phải có thể được truyền dưới dạng boolean. Đầu vào được chấp nhận là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

89,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

88,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

354,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

384,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

385 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

386

đã xác nhận

Trường được xác thực phải có trường phù hợp là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

387. Ví dụ: nếu trường được xác thực là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

388, thì trường

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

389 phù hợp phải có trong thông tin đầu vào

mật khẩu hiện tại

Trường được xác thực phải khớp với mật khẩu của người dùng được xác thực. Bạn có thể chỉ định một trình bảo vệ xác thực bằng cách sử dụng tham số đầu tiên của quy tắc

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

09

ngày tháng

Trường được xác thực phải là một ngày hợp lệ, không liên quan theo hàm PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

363

ngày_bằng. ngày tháng

Trường được xác thực phải bằng ngày đã cho. Các ngày sẽ được chuyển vào hàm PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

363 để được chuyển đổi thành một phiên bản

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

364 hợp lệ

Định dạng ngày tháng. định dạng,

Trường được xác thực phải khớp với một trong các định dạng đã cho. Bạn nên sử dụng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

375 hoặc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

394 khi xác thực một trường, không phải cả hai. Quy tắc xác thực này hỗ trợ tất cả các định dạng được hỗ trợ bởi lớp DateTime của PHP

số thập phân. nhỏ nhất lớn nhất

Trường được xác thực phải là số và phải chứa số vị trí thập phân đã chỉ định

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

40

suy giảm

Trường được xác thực phải là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

395,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

396,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

384 hoặc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

88

bị từ chối_if. trường khác, giá trị,

Trường đang được xác thực phải là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

395,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

396,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

384 hoặc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

88 nếu một trường khác đang được xác thực bằng một giá trị đã chỉ định

khác biệt. cánh đồng

Trường được xác thực phải có giá trị khác với trường

chữ số. giá trị

Số nguyên được xác thực phải có độ dài giá trị chính xác

chữ số_giữa. nhỏ nhất lớn nhất

Xác thực số nguyên phải có độ dài giữa tối thiểu và tối đa đã cho

kích thước

Tệp đang được xác thực phải là một hình ảnh đáp ứng các ràng buộc về kích thước như được chỉ định bởi các tham số của quy tắc

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

41

ràng buộc có sẵn là. min_width, max_width, min_height, max_height, chiều rộng, chiều cao, tỷ lệ

Một ràng buộc tỷ lệ phải được biểu diễn bằng chiều rộng chia cho chiều cao. Điều này có thể được chỉ định bằng một phân số như

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

603 hoặc số float như

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

604

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

42

Vì quy tắc này yêu cầu một số đối số, bạn có thể sử dụng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

605 để xây dựng quy tắc một cách trôi chảy

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

43

riêng biệt

Khi xác thực mảng, trường được xác thực không được có bất kỳ giá trị trùng lặp nào

Theo mặc định, Distinct sử dụng phép so sánh biến lỏng lẻo. Để sử dụng phép so sánh nghiêm ngặt, bạn có thể thêm tham số

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

606 vào định nghĩa quy tắc xác thực của mình

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

44

Bạn có thể thêm

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

607 vào các đối số của quy tắc xác thực để làm cho quy tắc bỏ qua sự khác biệt về cách viết hoa

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

45

không_bắt_đầu_với. thực phẩm, thanh,

Trường được xác thực không được bắt đầu bằng một trong các giá trị đã cho

không_cuối_với. thực phẩm, thanh,

Trường được xác thực không được kết thúc bằng một trong các giá trị đã cho

e-mail

Trường được xác thực phải được định dạng dưới dạng địa chỉ email. Quy tắc xác thực này sử dụng gói

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

608 để xác thực địa chỉ email. Theo mặc định, trình xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

609 được áp dụng nhưng bạn cũng có thể áp dụng các kiểu xác thực khác

Ví dụ trên sẽ áp dụng xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

609 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

611. Dưới đây là danh sách đầy đủ các kiểu xác thực mà bạn có thể áp dụng

  • namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    612.

    namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    609
  • namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    606.

    namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    615
  • namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    616.

    namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    611
  • namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    618.

    namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    619
  • namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    620.

    namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    621
  • namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    622.

    namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    623

Trình xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

620, sử dụng hàm

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

625 của PHP, đi kèm với Laravel và là hành vi xác thực email mặc định của Laravel trước phiên bản 5 của Laravel. 8

Cảnh báo
Trình xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

616 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

618 yêu cầu tiện ích mở rộng PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

628.

kết_với. thực phẩm, thanh,

Trường được xác thực phải kết thúc bằng một trong các giá trị đã cho

liệt kê

Quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

629 là quy tắc dựa trên lớp xác thực xem trường được xác thực có chứa giá trị enum hợp lệ hay không. Quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

629 chấp nhận tên của enum làm đối số hàm tạo duy nhất của nó

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

46

Cảnh báo
Enums chỉ khả dụng trên PHP 8. 1+.

loại trừ

Trường đang được xác thực sẽ bị loại trừ khỏi dữ liệu yêu cầu được trả về bởi phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

319

loại trừ_if. trường khác, giá trị

Trường đang được xác thực sẽ bị loại trừ khỏi dữ liệu yêu cầu được trả về bởi các phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

319 nếu trường otherfield bằng giá trị

Nếu logic loại trừ có điều kiện phức tạp được yêu cầu, bạn có thể sử dụng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

635. Phương pháp này chấp nhận một boolean hoặc một bao đóng. Khi được cung cấp một bao đóng, bao đóng phải trả về

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

89 hoặc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

88 để cho biết liệu trường đang được xác thực có nên bị loại trừ hay không

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

47

loại trừ_unless. trường khác, giá trị

Trường đang được xác thực sẽ bị loại trừ khỏi dữ liệu yêu cầu được trả về bởi các phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

319 trừ khi trường của trường khác bằng giá trị. Nếu giá trị là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59 [

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

641], trường được xác thực sẽ bị loại trừ trừ khi trường so sánh là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59 hoặc trường so sánh bị thiếu trong dữ liệu yêu cầu

loại trừ_với. lĩnh vực khác

Trường đang được xác thực sẽ bị loại trừ khỏi dữ liệu yêu cầu được trả về bởi các phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

319 nếu có trường otherfield

loại trừ_không. lĩnh vực khác

Trường đang được xác thực sẽ bị loại trừ khỏi dữ liệu yêu cầu được trả về bởi các phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

319 nếu trường otherfield không có mặt

tồn tại. bảng, cột

Trường được xác thực phải tồn tại trong một bảng cơ sở dữ liệu nhất định

Cách sử dụng cơ bản của quy tắc tồn tại

Nếu tùy chọn

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

647 không được chỉ định, tên trường sẽ được sử dụng. Vì vậy, trong trường hợp này, quy tắc sẽ xác thực rằng bảng cơ sở dữ liệu

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

648 chứa bản ghi có giá trị cột

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

649 khớp với giá trị thuộc tính

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

649 của yêu cầu

Chỉ định tên cột tùy chỉnh

Bạn có thể chỉ định rõ ràng tên cột cơ sở dữ liệu sẽ được sử dụng theo quy tắc xác thực bằng cách đặt nó sau tên bảng cơ sở dữ liệu

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

48

Đôi khi, bạn có thể cần chỉ định một kết nối cơ sở dữ liệu cụ thể sẽ được sử dụng cho truy vấn

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

651. Bạn có thể thực hiện việc này bằng cách thêm tên kết nối vào tên bảng

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

49

Thay vì chỉ định trực tiếp tên bảng, bạn có thể chỉ định mô hình Eloquent sẽ được sử dụng để xác định tên bảng

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

50

Nếu bạn muốn tùy chỉnh truy vấn được thực hiện theo quy tắc xác thực, bạn có thể sử dụng lớp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

652 để xác định quy tắc một cách trôi chảy. Trong ví dụ này, chúng tôi cũng sẽ chỉ định các quy tắc xác thực dưới dạng một mảng thay vì sử dụng ký tự

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

33 để phân định chúng

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

51

Bạn có thể chỉ định rõ ràng tên cột cơ sở dữ liệu sẽ được sử dụng bởi quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

651 được tạo bởi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

655 bằng cách cung cấp tên cột làm đối số thứ hai cho phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

651

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

52

tập tin

Trường được xác thực phải là tệp đã tải lên thành công

điền

Trường được xác thực không được để trống khi nó hiện diện

gt. cánh đồng

Trường được xác thực phải lớn hơn trường đã cho. Hai trường phải cùng loại. Các chuỗi, số, mảng và tệp được đánh giá bằng cách sử dụng các quy ước giống như quy tắc

gte. cánh đồng

Trường được xác thực phải lớn hơn hoặc bằng trường đã cho. Hai trường phải cùng loại. Các chuỗi, số, mảng và tệp được đánh giá bằng cách sử dụng các quy ước giống như quy tắc

hình ảnh

Tệp được xác thực phải là hình ảnh [jpg, jpeg, png, bmp, gif, svg hoặc webp]

Trong. thực phẩm, thanh,

Trường được xác thực phải được bao gồm trong danh sách giá trị đã cho. Vì quy tắc này thường yêu cầu bạn phải

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

659 một mảng, phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

660 có thể được sử dụng để xây dựng quy tắc một cách trôi chảy

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

53

Khi quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

661 được kết hợp với quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

305, mỗi giá trị trong mảng đầu vào phải có mặt trong danh sách các giá trị được cung cấp cho quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

661. Trong ví dụ sau, mã sân bay

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

664 trong mảng đầu vào không hợp lệ vì nó không có trong danh sách sân bay được cung cấp cho quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

661

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

54

in_array. lĩnh vực khác. *

Trường được xác thực phải tồn tại trong các giá trị của trường khác

số nguyên

Trường được xác thực phải là số nguyên

Cảnh báo
Quy tắc xác thực này không xác minh rằng đầu vào thuộc loại biến "số nguyên", chỉ xác minh rằng đầu vào thuộc loại được chấp nhận bởi quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

666 của PHP. Nếu bạn cần xác thực đầu vào là một số, vui lòng sử dụng quy tắc này kết hợp với.

ip

Trường được xác thực phải là địa chỉ IP

ipv4

Trường được xác thực phải là địa chỉ IPv4

ipv6

Trường được xác thực phải là địa chỉ IPv6

json

Trường được xác thực phải là một chuỗi JSON hợp lệ

trung úy. cánh đồng

Trường được xác thực phải nhỏ hơn trường đã cho. Hai trường phải cùng loại. Các chuỗi, số, mảng và tệp được đánh giá bằng cách sử dụng các quy ước giống như quy tắc

lte. cánh đồng

Trường được xác thực phải nhỏ hơn hoặc bằng trường đã cho. Hai trường phải cùng loại. Các chuỗi, số, mảng và tệp được đánh giá bằng cách sử dụng các quy ước giống như quy tắc

chữ thường

Trường được xác thực phải là chữ thường

địa chỉ MAC

Trường được xác thực phải là địa chỉ MAC

tối đa. giá trị

Trường được xác thực phải nhỏ hơn hoặc bằng giá trị tối đa. Các chuỗi, số, mảng và tệp được đánh giá theo cùng một kiểu với quy tắc

max_digits. giá trị

Số nguyên được xác thực phải có độ dài giá trị tối đa

kịch câm. văn bản/đồng bằng,

Tệp được xác thực phải khớp với một trong các loại MIME đã cho

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

55

Để xác định loại MIME của tệp đã tải lên, nội dung của tệp sẽ được đọc và khung sẽ cố gắng đoán loại MIME, loại này có thể khác với loại MIME do khách hàng cung cấp

kịch câm. thực phẩm, thanh,

Tệp đang được xác thực phải có loại MIME tương ứng với một trong các tiện ích mở rộng được liệt kê

Cách sử dụng cơ bản của quy tắc MIME

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

56

Mặc dù bạn chỉ cần chỉ định phần mở rộng, quy tắc này thực sự xác thực loại MIME của tệp bằng cách đọc nội dung của tệp và đoán loại MIME của nó. Có thể tìm thấy danh sách đầy đủ các loại MIME và các tiện ích mở rộng tương ứng của chúng tại vị trí sau

https. //svn. apache. org/repos/asf/httpd/httpd/trunk/docs/conf/mime. các loại

tối thiểu. giá trị

Trường được xác thực phải có giá trị tối thiểu. Các chuỗi, số, mảng và tệp được đánh giá theo cùng một kiểu với quy tắc

min_digits. giá trị

Số nguyên được xác thực phải có độ dài giá trị tối thiểu

multiple_of. giá trị

Trường được xác thực phải là bội số của giá trị

Cảnh báo
Cần có phần mở rộng PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

672 để sử dụng quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

673.

not_in. thực phẩm, thanh,

Trường được xác thực không được bao gồm trong danh sách giá trị đã cho. Phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

674 có thể được sử dụng để xây dựng thành thạo quy tắc

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

57

not_regex. mẫu

Trường được xác thực không được khớp với biểu thức chính quy đã cho

Trong nội bộ, quy tắc này sử dụng hàm PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

675. Mẫu được chỉ định phải tuân theo cùng định dạng theo yêu cầu của

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

675 và do đó cũng bao gồm các dấu phân cách hợp lệ. Ví dụ.

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

677

Cảnh báo
Khi sử dụng các mẫu

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

678 /

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

679, có thể cần chỉ định quy tắc xác thực của bạn bằng cách sử dụng một mảng thay vì sử dụng dấu phân cách

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

33, đặc biệt nếu biểu thức chính quy chứa ký tự

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

33.

vô giá trị

Trường được xác thực có thể là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59

con số

Trường được xác thực phải là số

mật khẩu mở khóa

Trường được xác thực phải khớp với mật khẩu của người dùng được xác thực

Cảnh báo
Quy tắc này đã được đổi tên thành

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

683 với ý định xóa nó trong Laravel 9. Vui lòng sử dụng quy tắc thay thế.

hiện nay

Trường được xác thực phải có trong dữ liệu đầu vào nhưng có thể để trống

Cấm

Trường được xác thực phải là một chuỗi trống hoặc không có

bị cấm_if. trường khác, giá trị,

Trường được xác thực phải là một chuỗi trống hoặc không có nếu trường otherfield bằng bất kỳ giá trị nào

Nếu logic cấm có điều kiện phức tạp được yêu cầu, bạn có thể sử dụng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

684. Phương pháp này chấp nhận một boolean hoặc một bao đóng. Khi được cung cấp một bao đóng, bao đóng phải trả về

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

89 hoặc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

88 để cho biết liệu trường đang được xác thực có nên bị cấm hay không

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

58

bị cấm_unless. trường khác, giá trị,

Trường được xác thực phải là một chuỗi trống hoặc không có trừ khi trường otherfield bằng bất kỳ giá trị nào

cấm. lĩnh vực khác,

Nếu có trường đang xác thực, thì không có trường nào trong trường khác có thể có, ngay cả khi trống

biểu thức chính quy. mẫu

Trường được xác thực phải khớp với biểu thức chính quy đã cho

Trong nội bộ, quy tắc này sử dụng hàm PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

675. Mẫu được chỉ định phải tuân theo cùng định dạng theo yêu cầu của

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

675 và do đó cũng bao gồm các dấu phân cách hợp lệ. Ví dụ.

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

689

Cảnh báo
Khi sử dụng các mẫu

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

678 /

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

679, có thể cần chỉ định các quy tắc trong một mảng thay vì sử dụng dấu phân cách

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

33, đặc biệt nếu biểu thức chính quy chứa ký tự

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

33.

cần thiết

Trường được xác thực phải có trong dữ liệu đầu vào và không trống. Một trường được coi là "trống" nếu một trong các điều kiện sau là đúng

  • Giá trị là

    namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    59
  • Giá trị là một chuỗi rỗng
  • Giá trị là một mảng trống hoặc đối tượng

    namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;

    use Illuminate\Http\Request;

    class PostController extends Controller

    * Show the form to create a new blog post.

    * @return \Illuminate\View\View

    return view['post.create'];

    * @param \Illuminate\Http\Request $request

    * @return \Illuminate\Http\Response

    public function store[Request $request]

    // Validate and store the blog post...

    695 trống
  • Giá trị là một tệp đã tải lên không có đường dẫn

bắt buộc_if. trường khác, giá trị,

Trường được xác thực phải có mặt và không trống nếu trường otherfield bằng bất kỳ giá trị nào

Nếu bạn muốn xây dựng một điều kiện phức tạp hơn cho quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

696, bạn có thể sử dụng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

697. Phương pháp này chấp nhận một boolean hoặc một bao đóng. Khi thông qua một lần đóng, lần đóng sẽ trả về

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

89 hoặc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

88 để cho biết trường được xác thực có bắt buộc không

use App\Http\Controllers\PostController;

Route::get['/post/create', [PostController::class, 'create']];

Route::post['/post', [PostController::class, 'store']];

59

bắt buộc_unless. trường khác, giá trị,

Trường được xác thực phải có mặt và không trống trừ khi trường otherfield bằng bất kỳ giá trị nào. Điều này cũng có nghĩa là trường khác phải có trong dữ liệu yêu cầu trừ khi giá trị là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59. Nếu giá trị là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59 [

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

802], trường được xác thực sẽ được yêu cầu trừ khi trường so sánh là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59 hoặc trường so sánh bị thiếu trong dữ liệu yêu cầu

bắt buộc_với. thực phẩm, thanh,

Trường được xác thực phải có mặt và không trống chỉ khi có bất kỳ trường nào được chỉ định khác có mặt và không trống

required_with_all. thực phẩm, thanh,

Trường được xác thực phải có mặt và không trống chỉ khi tất cả các trường được chỉ định khác có mặt và không trống

bắt buộc_không. thực phẩm, thanh,

Trường được xác thực phải có mặt và không trống chỉ khi bất kỳ trường nào được chỉ định khác trống hoặc không có

bắt buộc_không_có_tất_cả. thực phẩm, thanh,

Trường được xác thực phải có mặt và không trống chỉ khi tất cả các trường được chỉ định khác trống hoặc không có

required_array_keys. thực phẩm, thanh,

Trường được xác thực phải là một mảng và phải chứa ít nhất các khóa đã chỉ định

như nhau. cánh đồng

Trường đã cho phải khớp với trường đang được xác thực

kích thước. giá trị

Trường được xác thực phải có kích thước khớp với giá trị đã cho. Đối với dữ liệu chuỗi, giá trị tương ứng với số ký tự. Đối với dữ liệu số, giá trị tương ứng với một giá trị số nguyên nhất định [thuộc tính cũng phải có quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

667 hoặc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

805]. Đối với một mảng, kích thước tương ứng với

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

806 của mảng. Đối với tệp, kích thước tương ứng với kích thước tệp tính bằng kilobyte. Hãy xem xét một số ví dụ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

40

bắt đầu với. thực phẩm, thanh,

Trường được xác thực phải bắt đầu bằng một trong các giá trị đã cho

chuỗi

Trường được xác thực phải là một chuỗi. Nếu bạn muốn cho phép trường cũng là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

59, bạn nên gán quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

63 cho trường

Múi giờ

Trường được xác thực phải là mã định danh múi giờ hợp lệ theo hàm PHP

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

809

duy nhất. bảng, cột

Trường được xác thực không được tồn tại trong bảng cơ sở dữ liệu đã cho

Chỉ định tên bảng / cột tùy chỉnh

Thay vì chỉ định trực tiếp tên bảng, bạn có thể chỉ định mô hình Eloquent sẽ được sử dụng để xác định tên bảng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

41

Tùy chọn

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

647 có thể được sử dụng để chỉ định cột cơ sở dữ liệu tương ứng của trường. Nếu tùy chọn

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

647 không được chỉ định, tên của trường được xác thực sẽ được sử dụng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

42

Chỉ định kết nối cơ sở dữ liệu tùy chỉnh

Đôi khi, bạn có thể cần đặt kết nối tùy chỉnh cho các truy vấn cơ sở dữ liệu do Trình xác thực thực hiện. Để thực hiện điều này, bạn có thể thêm tên kết nối vào tên bảng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

43

Buộc một quy tắc duy nhất bỏ qua một ID đã cho

Đôi khi, bạn có thể muốn bỏ qua một ID nhất định trong quá trình xác thực duy nhất. Ví dụ: xem xét màn hình "cập nhật hồ sơ" bao gồm tên, địa chỉ email và vị trí của người dùng. Bạn có thể sẽ muốn xác minh rằng địa chỉ email là duy nhất. Tuy nhiên, nếu người dùng chỉ thay đổi trường tên chứ không phải trường email, bạn không muốn xảy ra lỗi xác thực vì người dùng đã là chủ sở hữu của địa chỉ email được đề cập

Để hướng dẫn trình xác thực bỏ qua ID của người dùng, chúng tôi sẽ sử dụng lớp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

652 để xác định quy tắc một cách trôi chảy. Trong ví dụ này, chúng tôi cũng sẽ chỉ định các quy tắc xác thực dưới dạng một mảng thay vì sử dụng ký tự

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

33 để phân định các quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

44

Cảnh báo
Bạn không bao giờ được chuyển bất kỳ đầu vào yêu cầu do người dùng kiểm soát nào vào phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

814. Thay vào đó, bạn chỉ nên chuyển một ID duy nhất do hệ thống tạo, chẳng hạn như ID tăng tự động hoặc UUID từ một phiên bản mô hình Eloquent. Nếu không, ứng dụng của bạn sẽ dễ bị tấn công SQL injection.

Thay vì chuyển giá trị của khóa mô hình sang phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

814, bạn cũng có thể chuyển toàn bộ phiên bản mô hình. Laravel sẽ tự động trích xuất khóa từ mô hình

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

45

Nếu bảng của bạn sử dụng tên cột khóa chính khác với tên cột

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

816, bạn có thể chỉ định tên của cột khi gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

814

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

46

Theo mặc định, quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

36 sẽ kiểm tra tính duy nhất của cột khớp với tên của thuộc tính đang được xác thực. Tuy nhiên, bạn có thể chuyển một tên cột khác làm đối số thứ hai cho phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

36

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

47

Thêm mệnh đề bổ sung

Bạn có thể chỉ định các điều kiện truy vấn bổ sung bằng cách tùy chỉnh truy vấn bằng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

820. Ví dụ: hãy thêm một điều kiện truy vấn để phạm vi truy vấn chỉ tìm kiếm các bản ghi có giá trị cột

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

821 là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

354

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

48

chữ hoa

Trường được xác thực phải là chữ hoa

url

Trường được xác thực phải là một URL hợp lệ

ulid

Trường được xác thực phải là Mã định danh có thể sắp xếp theo từ điển duy nhất toàn cầu [ULID] hợp lệ

uuid

Trường được xác thực phải là số nhận dạng duy nhất toàn cầu RFC 4122 [phiên bản 1, 3, 4 hoặc 5] hợp lệ [UUID]

Thêm quy tắc có điều kiện

Bỏ qua xác thực khi các trường có giá trị nhất định

Đôi khi, bạn có thể không muốn xác thực một trường nhất định nếu một trường khác có một giá trị nhất định. Bạn có thể thực hiện việc này bằng cách sử dụng quy tắc xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

823. Trong ví dụ này, các trường

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

824 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

825 sẽ không được xác thực nếu trường

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

826 có giá trị là

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

88

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

49

Ngoài ra, bạn có thể sử dụng quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

828 để không xác thực một trường nhất định trừ khi một trường khác có giá trị nhất định

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

10

Xác thực khi có mặt

Trong một số trường hợp, bạn có thể muốn chạy kiểm tra xác thực đối với một trường chỉ khi trường đó có trong dữ liệu đang được xác thực. Để nhanh chóng hoàn thành việc này, hãy thêm quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

829 vào danh sách quy tắc của bạn

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

11

Trong ví dụ trên, trường

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

830 sẽ chỉ được xác thực nếu nó có trong mảng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

831

Lưu ý
Nếu bạn đang cố xác thực một trường phải luôn hiện diện nhưng có thể trống, hãy kiểm tra.

Xác thực có điều kiện phức tạp

Đôi khi bạn có thể muốn thêm các quy tắc xác thực dựa trên logic điều kiện phức tạp hơn. Ví dụ: bạn có thể chỉ muốn yêu cầu một trường nhất định nếu trường khác có giá trị lớn hơn 100. Hoặc, bạn có thể cần hai trường để chỉ có một giá trị nhất định khi có trường khác. Thêm các quy tắc xác thực này không phải là một điều khó khăn. Đầu tiên, tạo một phiên bản

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

98 với các quy tắc tĩnh không bao giờ thay đổi của bạn

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

12

Giả sử ứng dụng web của chúng tôi dành cho người sưu tầm trò chơi. Nếu một nhà sưu tập trò chơi đăng ký với ứng dụng của chúng tôi và họ sở hữu hơn 100 trò chơi, chúng tôi muốn họ giải thích lý do tại sao họ sở hữu nhiều trò chơi như vậy. Ví dụ: có lẽ họ điều hành một cửa hàng bán lại trò chơi hoặc có thể họ chỉ thích sưu tập trò chơi. Để thêm yêu cầu này một cách có điều kiện, chúng ta có thể sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

829 trên trường hợp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

98

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

13

Đối số đầu tiên được truyền cho phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

829 là tên của trường chúng tôi đang xác thực có điều kiện. Đối số thứ hai là danh sách các quy tắc chúng tôi muốn thêm. Nếu lệnh đóng được thông qua khi đối số thứ ba trả về

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

89, các quy tắc sẽ được thêm vào. Phương pháp này giúp dễ dàng xây dựng các xác thực có điều kiện phức tạp. Bạn thậm chí có thể thêm xác thực có điều kiện cho một số trường cùng một lúc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

14

Lưu ý
Tham số

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

837 được truyền cho lần đóng của bạn sẽ là một phiên bản của

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

838 và có thể được sử dụng để truy cập thông tin đầu vào và tệp của bạn đang được xác thực.

Xác thực mảng có điều kiện phức tạp

Đôi khi, bạn có thể muốn xác thực một trường dựa trên một trường khác trong cùng một mảng lồng nhau có chỉ mục mà bạn không biết. Trong những tình huống này, bạn có thể cho phép bao đóng của mình nhận đối số thứ hai sẽ là mục riêng lẻ hiện tại trong mảng đang được xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

15

Giống như tham số

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

837 được truyền cho bao đóng, tham số

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

840 là một thể hiện của

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

838 khi dữ liệu thuộc tính là một mảng;

Xác thực mảng

Như đã thảo luận trong phần , quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

305 chấp nhận danh sách các khóa mảng được phép. Nếu có bất kỳ khóa bổ sung nào trong mảng, quá trình xác thực sẽ không thành công

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

16

Nói chung, bạn phải luôn chỉ định các khóa mảng được phép có trong mảng của mình. Mặt khác, các phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

21 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

319 của trình xác thực sẽ trả về tất cả dữ liệu đã xác thực, bao gồm mảng và tất cả các khóa của nó, ngay cả khi các khóa đó không được xác thực bởi các quy tắc xác thực mảng lồng nhau khác

Xác thực đầu vào mảng lồng nhau

Việc xác thực các trường nhập biểu mẫu dựa trên mảng lồng nhau không phải là một điều khó khăn. Bạn có thể sử dụng "ký hiệu dấu chấm" để xác thực các thuộc tính trong một mảng. Ví dụ: nếu yêu cầu HTTP đến chứa trường

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

846, bạn có thể xác thực trường đó như sau

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

17

Bạn cũng có thể xác thực từng phần tử của một mảng. Ví dụ: để xác thực rằng mỗi email trong trường nhập mảng nhất định là duy nhất, bạn có thể thực hiện như sau

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

18

Tương tự như vậy, bạn có thể sử dụng ký tự

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

335 khi chỉ định , giúp dễ dàng sử dụng một thông báo xác thực duy nhất cho các trường dựa trên mảng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

19

Truy cập dữ liệu mảng lồng nhau

Đôi khi bạn có thể cần truy cập giá trị cho phần tử mảng lồng nhau đã cho khi gán quy tắc xác thực cho thuộc tính. Bạn có thể thực hiện việc này bằng cách sử dụng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

848. Phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

849 chấp nhận một bao đóng sẽ được gọi cho mỗi lần lặp của thuộc tính mảng được xác thực và sẽ nhận được giá trị của thuộc tính và tên thuộc tính rõ ràng, được mở rộng đầy đủ. Việc đóng sẽ trả về một mảng các quy tắc để gán cho phần tử mảng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

00

Thông báo Lỗi Chỉ mục & Vị trí

Khi xác thực mảng, bạn có thể muốn tham chiếu chỉ mục hoặc vị trí của một mục cụ thể không xác thực được trong thông báo lỗi được hiển thị bởi ứng dụng của bạn. Để thực hiện điều này, bạn có thể bao gồm các trình giữ chỗ

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

850 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

851 trong

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

01

Với ví dụ trên, quá trình xác thực sẽ không thành công và người dùng sẽ gặp lỗi sau "Vui lòng mô tả ảnh #2. "

Xác thực tập tin

Laravel cung cấp nhiều quy tắc xác thực có thể được sử dụng để xác thực các tệp đã tải lên, chẳng hạn như

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

852,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

853,

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

854 và

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

38. Mặc dù bạn có thể tự do chỉ định các quy tắc này riêng lẻ khi xác thực tệp, Laravel cũng cung cấp trình tạo quy tắc xác thực tệp thông thạo mà bạn có thể thấy thuận tiện.

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

02

Nếu ứng dụng của bạn chấp nhận hình ảnh do người dùng của bạn tải lên, bạn có thể sử dụng phương thức xây dựng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

853 của quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

856 để cho biết rằng tệp đã tải lên phải là hình ảnh. Ngoài ra, quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

858 có thể được sử dụng để giới hạn kích thước của hình ảnh

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

03

Lưu ý
Bạn có thể tìm thêm thông tin về việc xác thực kích thước hình ảnh trong.

Loại tập tin

Mặc dù bạn chỉ cần chỉ định phần mở rộng khi gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

859, phương thức này thực sự xác thực loại MIME của tệp bằng cách đọc nội dung của tệp và đoán loại MIME của nó. Có thể tìm thấy danh sách đầy đủ các loại MIME và các tiện ích mở rộng tương ứng của chúng tại vị trí sau

https. //svn. apache. org/repos/asf/httpd/httpd/trunk/docs/conf/mime. các loại

Xác thực mật khẩu

Để đảm bảo rằng mật khẩu có mức độ phức tạp phù hợp, bạn có thể sử dụng đối tượng quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

860 của Laravel

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

04

Đối tượng quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

860 cho phép bạn dễ dàng tùy chỉnh các yêu cầu về độ phức tạp của mật khẩu cho ứng dụng của mình, chẳng hạn như chỉ định rằng mật khẩu yêu cầu ít nhất một chữ cái, số, ký hiệu hoặc ký tự có viết hoa hỗn hợp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

05

Ngoài ra, bạn có thể đảm bảo rằng mật khẩu không bị xâm phạm trong vụ rò rỉ dữ liệu mật khẩu công khai bằng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

862

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

06

Trong nội bộ, đối tượng quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

860 sử dụng mô hình k-Anonymity để xác định xem mật khẩu có bị rò rỉ thông qua haveibeenpwned hay không. com mà không làm mất quyền riêng tư hoặc bảo mật của người dùng

Theo mặc định, nếu mật khẩu xuất hiện ít nhất một lần trong một lần rò rỉ dữ liệu, mật khẩu đó sẽ bị coi là bị xâm phạm. Bạn có thể tùy chỉnh ngưỡng này bằng đối số đầu tiên của phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

862

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

07

Tất nhiên, bạn có thể xâu chuỗi tất cả các phương thức trong các ví dụ trên

Xác định quy tắc mật khẩu mặc định

Bạn có thể thấy thuận tiện khi chỉ định các quy tắc xác thực mặc định cho mật khẩu ở một vị trí duy nhất trong ứng dụng của mình. Bạn có thể dễ dàng thực hiện việc này bằng cách sử dụng phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

865, phương thức này chấp nhận một bao đóng. Việc đóng cho phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

866 sẽ trả về cấu hình mặc định của quy tắc Mật khẩu. Thông thường, quy tắc

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

866 nên được gọi trong phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

868 của một trong những nhà cung cấp dịch vụ ứng dụng của bạn

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

08

Sau đó, khi bạn muốn áp dụng các quy tắc mặc định cho một mật khẩu cụ thể đang được xác thực, bạn có thể gọi phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

866 mà không có đối số

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

09

Đôi khi, bạn có thể muốn đính kèm các quy tắc xác thực bổ sung vào quy tắc xác thực mật khẩu mặc định của mình. Bạn có thể sử dụng phương pháp

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

75 để thực hiện điều này

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

10

Quy tắc xác thực tùy chỉnh

Sử dụng đối tượng quy tắc

Laravel cung cấp nhiều quy tắc xác thực hữu ích; . Một phương pháp đăng ký quy tắc xác thực tùy chỉnh là sử dụng các đối tượng quy tắc. Để tạo một đối tượng quy tắc mới, bạn có thể sử dụng lệnh Artisan

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

871. Hãy sử dụng lệnh này để tạo quy tắc xác minh một chuỗi là chữ hoa. Laravel sẽ đặt quy tắc mới trong thư mục

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

872. Nếu thư mục này không tồn tại, Laravel sẽ tạo nó khi bạn thực thi lệnh Artisan để tạo quy tắc của mình

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

11

Khi quy tắc đã được tạo, chúng tôi sẵn sàng xác định hành vi của nó. Một đối tượng quy tắc chứa một phương thức duy nhất.

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

873. Phương thức này nhận tên thuộc tính, giá trị của nó và một cuộc gọi lại sẽ được gọi khi không thành công với thông báo lỗi xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

12

Khi quy tắc đã được xác định, bạn có thể đính kèm nó vào trình xác thực bằng cách chuyển một phiên bản của đối tượng quy tắc với các quy tắc xác thực khác của bạn

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

13

Dịch thông báo xác thực

Thay vì cung cấp thông báo lỗi theo nghĩa đen cho phần đóng

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

874, bạn cũng có thể cung cấp khóa chuỗi dịch và hướng dẫn Laravel dịch thông báo lỗi

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

14

Nếu cần, bạn có thể cung cấp các thay thế trình giữ chỗ và ngôn ngữ ưa thích làm đối số thứ nhất và thứ hai cho phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

875

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

15

Truy cập dữ liệu bổ sung

Nếu lớp quy tắc xác thực tùy chỉnh của bạn cần truy cập vào tất cả dữ liệu khác đang được xác thực, thì lớp quy tắc của bạn có thể triển khai giao diện

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

876. Giao diện này yêu cầu lớp của bạn xác định phương thức

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

877. Phương thức này sẽ tự động được gọi bởi Laravel [trước khi tiến hành xác thực] với tất cả dữ liệu đang được xác thực

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

16

Hoặc, nếu quy tắc xác thực của bạn yêu cầu quyền truy cập vào phiên bản trình xác thực đang thực hiện xác thực, thì bạn có thể triển khai giao diện

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

878

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

17

Sử dụng Closures

Nếu bạn chỉ cần chức năng của quy tắc tùy chỉnh một lần trong ứng dụng của mình, thì bạn có thể sử dụng bao đóng thay vì đối tượng quy tắc. Việc đóng nhận tên của thuộc tính, giá trị của thuộc tính và gọi lại

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

874 sẽ được gọi nếu xác thực không thành công

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

18

Quy tắc ngầm

Theo mặc định, khi một thuộc tính đang được xác thực không có hoặc chứa một chuỗi trống, thì các quy tắc xác thực thông thường, bao gồm các quy tắc tùy chỉnh, sẽ không được chạy. Ví dụ: quy tắc sẽ không được chạy đối với một chuỗi trống

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

19

Để quy tắc tùy chỉnh chạy ngay cả khi thuộc tính trống, quy tắc phải ngụ ý rằng thuộc tính là bắt buộc. Để tạo nhanh một đối tượng quy tắc ẩn mới, bạn có thể sử dụng lệnh Artisan

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

871 với tùy chọn

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class PostController extends Controller

* Show the form to create a new blog post.

* @return \Illuminate\View\View

return view['post.create'];

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

public function store[Request $request]

// Validate and store the blog post...

882

Chủ Đề