học laravel 5

Bài 8 : Form trong Laravel 5

Ở bài trước, mình đã hướng dẫn cho các bạn về mô hình MVC trong Laravel 5, đồng thời nắm được cách mà dữ liệu được hiển thị từ bên trong model ra ngoài view như thế nào. Trong bài hôm nay chúng ta sẽ cùng nhau tiếp tục tìm hiểu cách lưu dữ liệu vào bên trong database thông qua thông qua ví dụ tạo form trong Laravel 5.

Form trong Laravel 5

Laravel 5 hỗ trợ chúng ta tạo form một cách dễ dàng thông qua các hàm đã xây dựng sẵn. Trong bài viết này mình sẽ hướng dẫn các bạn tạo 1 form dùng để lưu thông tin bài viết vào bảng articles mà chúng ta đã sử dụng ở các bài trước.

1. Thêm routes

Mình sẽ thêm một route mới dùng để hiển thị form cho người dùng nhập thông tin, route này sẽ có nhiệm vụ gọi tới function create() trong ArticlesController

Route::get('/articles/create', 'ArticlesController@create');

2. Sửa file controller ArticlesController.php

Bên trong file ArticlesControllers.php đã tạo ở bài trước, mình thêm một function mới gọi là create() ứng với route đã được tạo. Function này sẽ có trách nhiệm gọi view là create.blade.php để hiện thị form

public function create(){
    return view("create");
}

3. Cài đặt gói service HtmlServiceProvider

Để có thể sử dụng form trong Laravel 5, chúng ta cần phải cài đặt thêm gói HtmlServiceProvider, vì Laravel khi cài đặt ban đầu chưa tích hợp nó vào. HtmlServiceProvider cung cấp các phương thức đã xây dựng sẵn giúp chúng ta thao tác với form được dễ dàng hơn.

Để download cài đặt gói HtmlServiceProvider, mình mở cmd, gõ lệnh sau:

composer require illuminate/html

các bạn đợi khoảng vài giây để tiến trình cài đặt diễn ra như dưới đây :

Using version ~5.0 for illuminate/html
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)

Tiếp đến, sau khi đã cài đặt xong ServiceHtmlProvider, các bạn mở config/app.php, tìm đến các dòng chứa các provider của Laravel :

	'providers' => [

		/*
		 * Laravel Framework Service Providers...
		 */
		'Illuminate\Foundation\Providers\ArtisanServiceProvider',
		'Illuminate\Auth\AuthServiceProvider',
		'Illuminate\Bus\BusServiceProvider',
		'Illuminate\Cache\CacheServiceProvider',
		'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
		'Illuminate\Routing\ControllerServiceProvider',
		'Illuminate\Cookie\CookieServiceProvider',
		'Illuminate\Database\DatabaseServiceProvider',
		'Illuminate\Encryption\EncryptionServiceProvider',
		'Illuminate\Filesystem\FilesystemServiceProvider',
		'Illuminate\Foundation\Providers\FoundationServiceProvider',
		'Illuminate\Hashing\HashServiceProvider',
		'Illuminate\Mail\MailServiceProvider',
		'Illuminate\Pagination\PaginationServiceProvider',
		'Illuminate\Pipeline\PipelineServiceProvider',
		'Illuminate\Queue\QueueServiceProvider',
		'Illuminate\Redis\RedisServiceProvider',
		'Illuminate\Auth\Passwords\PasswordResetServiceProvider',
		'Illuminate\Session\SessionServiceProvider',
		'Illuminate\Translation\TranslationServiceProvider',
		'Illuminate\Validation\ValidationServiceProvider',
		'Illuminate\View\ViewServiceProvider',

và thêm 1 HtmlServiceProvider mới

'Illuminate\Html\HtmlServiceProvider',

vào ở cuối  như sau :

	'providers' => [

		/*
		 * Laravel Framework Service Providers...
		 */
		'Illuminate\Foundation\Providers\ArtisanServiceProvider',
		'Illuminate\Auth\AuthServiceProvider',
		'Illuminate\Bus\BusServiceProvider',
		'Illuminate\Cache\CacheServiceProvider',
		'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
		'Illuminate\Routing\ControllerServiceProvider',
		'Illuminate\Cookie\CookieServiceProvider',
		'Illuminate\Database\DatabaseServiceProvider',
		'Illuminate\Encryption\EncryptionServiceProvider',
		'Illuminate\Filesystem\FilesystemServiceProvider',
		'Illuminate\Foundation\Providers\FoundationServiceProvider',
		'Illuminate\Hashing\HashServiceProvider',
		'Illuminate\Mail\MailServiceProvider',
		'Illuminate\Pagination\PaginationServiceProvider',
		'Illuminate\Pipeline\PipelineServiceProvider',
		'Illuminate\Queue\QueueServiceProvider',
		'Illuminate\Redis\RedisServiceProvider',
		'Illuminate\Auth\Passwords\PasswordResetServiceProvider',
		'Illuminate\Session\SessionServiceProvider',
		'Illuminate\Translation\TranslationServiceProvider',
		'Illuminate\Validation\ValidationServiceProvider',
		'Illuminate\View\ViewServiceProvider',
		'Illuminate\Html\HtmlServiceProvider',

Tiếp đến các bạn tìm đến dòng chứa các aliases

	'aliases' => [

		'App'       => 'Illuminate\Support\Facades\App',
		'Artisan'   => 'Illuminate\Support\Facades\Artisan',
		'Auth'      => 'Illuminate\Support\Facades\Auth',
		'Blade'     => 'Illuminate\Support\Facades\Blade',
		'Bus'       => 'Illuminate\Support\Facades\Bus',
		'Cache'     => 'Illuminate\Support\Facades\Cache',
		'Config'    => 'Illuminate\Support\Facades\Config',
		'Cookie'    => 'Illuminate\Support\Facades\Cookie',
		'Crypt'     => 'Illuminate\Support\Facades\Crypt',
		'DB'        => 'Illuminate\Support\Facades\DB',
		'Eloquent'  => 'Illuminate\Database\Eloquent\Model',
		'Event'     => 'Illuminate\Support\Facades\Event',
		'File'      => 'Illuminate\Support\Facades\File',
		'Hash'      => 'Illuminate\Support\Facades\Hash',
		'Input'     => 'Illuminate\Support\Facades\Input',
		'Inspiring' => 'Illuminate\Foundation\Inspiring',
		'Lang'      => 'Illuminate\Support\Facades\Lang',
		'Log'       => 'Illuminate\Support\Facades\Log',
		'Mail'      => 'Illuminate\Support\Facades\Mail',
		'Password'  => 'Illuminate\Support\Facades\Password',
		'Queue'     => 'Illuminate\Support\Facades\Queue',
		'Redirect'  => 'Illuminate\Support\Facades\Redirect',
		'Redis'     => 'Illuminate\Support\Facades\Redis',
		'Request'   => 'Illuminate\Support\Facades\Request',
		'Response'  => 'Illuminate\Support\Facades\Response',
		'Route'     => 'Illuminate\Support\Facades\Route',
		'Schema'    => 'Illuminate\Support\Facades\Schema',
		'Session'   => 'Illuminate\Support\Facades\Session',
		'Storage'   => 'Illuminate\Support\Facades\Storage',
		'URL'       => 'Illuminate\Support\Facades\URL',
		'Validator' => 'Illuminate\Support\Facades\Validator',
		'View'      => 'Illuminate\Support\Facades\View',

	],

và thêm 2 alias mới là Form và Html

		'Form'      => 'Illuminate\Html\FormFacade',
		'View'      => 'Illuminate\Html\HtmlFacade',

vào cuối như sau :

	'aliases' => [

		'App'       => 'Illuminate\Support\Facades\App',
		'Artisan'   => 'Illuminate\Support\Facades\Artisan',
		'Auth'      => 'Illuminate\Support\Facades\Auth',
		'Blade'     => 'Illuminate\Support\Facades\Blade',
		'Bus'       => 'Illuminate\Support\Facades\Bus',
		'Cache'     => 'Illuminate\Support\Facades\Cache',
		'Config'    => 'Illuminate\Support\Facades\Config',
		'Cookie'    => 'Illuminate\Support\Facades\Cookie',
		'Crypt'     => 'Illuminate\Support\Facades\Crypt',
		'DB'        => 'Illuminate\Support\Facades\DB',
		'Eloquent'  => 'Illuminate\Database\Eloquent\Model',
		'Event'     => 'Illuminate\Support\Facades\Event',
		'File'      => 'Illuminate\Support\Facades\File',
		'Hash'      => 'Illuminate\Support\Facades\Hash',
		'Input'     => 'Illuminate\Support\Facades\Input',
		'Inspiring' => 'Illuminate\Foundation\Inspiring',
		'Lang'      => 'Illuminate\Support\Facades\Lang',
		'Log'       => 'Illuminate\Support\Facades\Log',
		'Mail'      => 'Illuminate\Support\Facades\Mail',
		'Password'  => 'Illuminate\Support\Facades\Password',
		'Queue'     => 'Illuminate\Support\Facades\Queue',
		'Redirect'  => 'Illuminate\Support\Facades\Redirect',
		'Redis'     => 'Illuminate\Support\Facades\Redis',
		'Request'   => 'Illuminate\Support\Facades\Request',
		'Response'  => 'Illuminate\Support\Facades\Response',
		'Route'     => 'Illuminate\Support\Facades\Route',
		'Schema'    => 'Illuminate\Support\Facades\Schema',
		'Session'   => 'Illuminate\Support\Facades\Session',
		'Storage'   => 'Illuminate\Support\Facades\Storage',
		'URL'       => 'Illuminate\Support\Facades\URL',
		'Validator' => 'Illuminate\Support\Facades\Validator',
		'View'      => 'Illuminate\Support\Facades\View',
		'Form'      => 'Illuminate\Html\FormFacade',
		'View'      => 'Illuminate\Html\HtmlFacade',

	],

Đến đây chúng ta đã setup các yêu cầu cần thiết để có thể sử dụng form trong laravel 5. Tiếp đến chúng ta sẽ tạo view để hiển thị form.

Gợi ý : Bạn là người mới và muốn tìm hiểu về Bitcoin nhưng không biết bắt đầu từ đâu? Click xem ngay Hướng Dẫn Đầu Tư Bitcoin Cho Người Mới nhé!

Gợi ý: Tặng coupon 40% giá trị khóa học tạo website với Laravel 5

4. Tạo view

Trong thư mục view, tiếp tục tạo file view như đã nhắc ở trên là create.blade.php có nội dung như sau :

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Form trong Laravel 5</title>
</head>
<body>
	<h1>Them Bai Viet Moi</h1>
	{!! Form::open() !!}

	{!! Form::close() !!}
</body>
</html>

Lưu lại, sau đó bật cmd gõ lệnh sau để chạy server laravel

php artisan serve

bạn sẽ thấy message trả về là

Laravel development server started on http://localhost:8000

vào trình duyệt gõ đường dẫn sau :

http://localhost:8000/articles/create

1 trang trắng sẽ hiện ra với tiêu đề là Them Bai Viet Moi vì lúc này chúng ta chỉ mới tạo thẻ form chứ chưa tạo bất cứ một input nào cả. Dùng Inspect Element trong chrome hoặc firefox (nhấn F12 hoặc trên trình duyệt, click chuột phải chọn Inspect Implement) , bạn sẽ thấy một thẻ form đã được tạo ra như hình dưới

form trong laravel 5
thẻ form trong laravel 5

Các bạn thấy đó, rõ ràng với cách viết đơn giản

{!! Form::open() !!}

{!! Form::close() !!}

Laravel đã tự động tạo ra cho chúng ta thẻ form với method là POST, còn action là đường dẫn gọi tới route hiện tại của chúng ta.

Tiếp theo, mình sẽ thêm 1 input mới gọi là name và có label là Name vào thẻ form như sau :

{!! Form::open() !!}
  {!! Form::label('name','Name:') !!}
  {!! Form::text('name') !!}
{!! Form::close() !!}		

Chạy lại đường dẫn trên bạn sẽ thấy 1 thẻ input mới được tạo ra như hình dưới

Tạo thẻ input trong form laravel 5
Tạo thẻ inut trong form

Tương tự, mình thêm 1 input mới gọi là author và button submit form:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Form trong Laravel 5</title>
</head>
<body>
	<h1>Them Bai Viet Moi</h1>
	{!! Form::open() !!}
		{!! Form::label('name','Name:') !!}
		{!! Form::text('name') !!} <br />

		{!! Form::label('author','Author:') !!}
		{!! Form::text('author') !!} </br>

		{!! Form::submit('Them moi')!!}
	{!! Form::close() !!}
</body>
</html>

Chạy lại đường dẫn, bạn sẽ thấy như thế này

submit form trong laravel 5
form trong laravel 5

Vậy là chúng ta đã thiết kế xong 1 form đơn giản trong Laravel 5. Tiếp đến mình sẽ viết code để khi người dùng họ điền thông tin vào các input và ấn submit form, ta sẽ tiến hành lưu các gía trị này vào database.

Có thể bạn quan tâm: Tặng coupon 40% giá trị khóa học tạo website với Laravel 5

5. Lấy gía trị từ form

Ở mục 4 trên, các bạn thấy action của thẻ form mặc định đang gọi tới route hiện hành của chúng ta là

http://localhost:8000/articles/create

Nhưng ở đây mình muốn khi submit form sẽ chạy vào một route mới gọi là articles, nên mình sẽ edit lại action của form một chút như sau

{!! Form::open(['url' => 'articles']) !!}

điều này đồng nghĩa với việc bạn phải tạo một route mới là articles với method là POST trong file routes.php

Route::post('/articles', 'ArticlesController@store');

route này có nhiệm vụ chuyển hướng data từ các thẻ input khi submit form bằng phương thức POST tới function store() trong ArticlesController. Vì thế trong ArticlesController.php mình sẽ thêm 1 function mới gọi là store() có nội dung sau:

public function store(Request $request){
	$dulieu_tu_input = $request->all();

	return $dulieu_tu_input;
}

Các bạn lưu ý là để có thể lấy được thông tin từ các input, thì bạn phải truyền đối tượng Request vào bên trong hàm store của chúng ta.

Chạy lại đường dẫn, điền thông tin vào các thẻ input (ở đây input name mình điền là “hieu”, input author điền “kungfuphp”) và ấn button Them moi, mình sẽ lấy được các thông tin được POST đi từ form dưới dạng json như sau.

{"_token":"9iLt4QJnr4BmzbbvpQhR6YCmpNOiCf2cpc06xGvr","name":"hieu","author":"kungfuphp"}

6. Lưu gía trị lấy được vào database

Sau khi các bạn đã lấy được gía trị từ form, việc tiếp theo thì chúng ta sẽ thực hiện lưu dữ liệu lấy được này vào database.

Mình sửa lại function store() một chút như sau :

public function store(Request $request){
		$dulieu_tu_input = $request->all();

		//Gọi model Articles.php đã được tạo ra ở các bài trước
		$articles = new Articles;

		//Lấy thông tin từ các input đưa vào thuộc tính name, author
                //trong model Articles
		$articles->name = $dulieu_tu_input["name"];
		$articles->author = $dulieu_tu_input["author"];

		//Tiến hành lưu dữ liệu vào database
		$articles->save();

		//Sau khi đã lưu xong, tiến hành chuyển hướng tới route articles
                //hiển thị toàn bộ thông tin bảng articles trong database đã được tạo ở các bài trước
		return redirect('articles');
	}

Chạy lại url điền thông tin và ấn Them moi, bạn sẽ được chuyển hướng tới trang http://localhost:8000/articles, với thông tin hiển thị ra là thông tin bạn đã lưu vào database :

Name : hieu | Author : kungfuphp.com
Name : trung | Author : hehehee
Name : google.com | Author : kungfuphp.com
Name : apple.com | Author : kungfuphp.com

Tổng kết : Bài viết này mình đã chia sẽ tới các bạn về tạo form trong laravel 5 và cách mà dữ liệu nhập từ form được lưu vào trong database như thế nào. Chúc các bạn học tốt !

Xem thêm : Khóa học tạo website hoàn chỉnh với Laravel 5 tặng mã giảm giá 40% + Hỗ trợ việc làm sau khi học xong

 

Có ích

học laravel 5

Bài 7 : Mô hình MVC trong Laravel 5

Trong bài hướng dẫn sử dụng Eloquent trong Laravel 5, các bạn đã có kiến …

37 bình luận

  1. Sao mình cài xong cái này : composer require illuminate/html
    Giờ vào lại trang thì gặp lỗi này: ” Fatal error: Cannot redeclare random_int() in E:\xampp\htdocs\demo\config\vendor\paragonie\random_compat\lib\random_int.php on line 191 ”
    Version php: 7.0
    Laravel: 5.3.24

    Đã tìm đủ cách vẫn chưa hiểu nguyên nhân, ai có thể giúp mình không vậy

  2. Tạo form như này thì CSS cho nó như nào nhỉ

  3. cái sử dụng port 8000 này là sao? nếu vậy sau này tất cả các trang có form là đều chuyển qua :8000 hết à đca

  4. Các bạn sài Laravel version 5.2 có thể tham khảo 2 bài này để cài đặt vì version 5.2 đã không còn sử dụng composer illuminate/html nữa.
    https://laravelcollective.com/docs/5.2/html#installation
    http://stackoverflow.com/questions/31520667/laravel-5-and-illuminate-html/34991188#34991188

  5. anh ơi cho em hỏi, nếu em tạo form bằng cái này thì làm thế nào để tạo form đẹp, kiểu dùng css, hay boottrap như nào vậy anh. Những cái tiện lợi hơn so với việc ngồi viết bằng html như nào vậy anh.
    Nhân tiện rất cảm ơn anh vì các bài học ^^

  6. D:\xampp\htdocs\laravel-5>php artisan serve
    PHP Fatal error: Call to undefined method Illuminate\Foundation\Application::bindShared() in D:\xampp\htdocs\laravel-5\vendor\illuminate\html\HtmlServiceProvider.php on line 36

    [Symfony\Component\Debug\Exception\FatalErrorException]
    Call to undefined method Illuminate\Foundation\Application::bindShared()mk chạy server thì bị lỗi này sửa sao ad?

  7. FatalErrorException in HtmlServiceProvider.php line 36:
    Call to undefined method Illuminate\Foundation\Application::bindShared()

    em bị lỗi này thì giải quyết sao vậy mấy pro

  8. public function store(Request $request)
    {
    $dulieu_tu_input = $request->all();

    //Gọi model Articles.php đã được tạo ra ở các bài trước
    $articles = new Articles;

    //Lấy thông tin từ các input đưa vào thuộc tính name, author
    //trong model Articles
    $articles->name = $dulieu_tu_input[“name”];
    $articles->author = $dulieu_tu_input[“author”];

    //Tiến hành lưu dữ liệu vào database
    $articles->save();

    //Sau khi đã lưu xong, tiến hành chuyển hướng tới route article
    //hiển thị toàn bộ thông tin bảng articles trong database đã được tạo ở các bài trước
    return redirect(‘articles’);
    }

    mình làm được tới đó khi mình chạy http://localhost:8000/articles/create thì nó báo lỗi này là sao ad
    1/1 ErrorException in ArticlesController.php line 34: Undefined index: name

  9. ad xem hộ mình lỗi này với…………………………….
    Whoops, looks like something went wrong.

    1/1
    InvalidArgumentException in FileViewFinder.php line 137:
    View [create] not found.

    • ad xem hộ mình lỗi này với…………………………….
      Whoops, looks like something went wrong.

      1/1
      InvalidArgumentException in FileViewFinder.php line 137:
      View [create] not found.

  10. thế thì css forrm như nào hả bạn ơi

  11. Anh ơi, post thêm nhiều bài nữa anh nhé. Bài hay quá. Cảm ơn anh nhiều. Chờ đợi các bài viết tiếp của anh!

  12. sao file app.php cua mình khác của bạn nhỉ: Duoi đây là 2 đoạn trong file của mình. Khi minh thêm vào thì nó báo lôi 🙁

    ‘providers’ => [

    /*
    * Laravel Framework Service Providers…
    */
    Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
    Illuminate\Auth\AuthServiceProvider::class,
    Illuminate\Broadcasting\BroadcastServiceProvider::class,
    Illuminate\Bus\BusServiceProvider::class,
    …..
    …..

    ‘aliases’ => [

    ‘App’ => Illuminate\Support\Facades\App::class,
    ‘Artisan’ => Illuminate\Support\Facades\Artisan::class,
    ‘Auth’ => Illuminate\Support\Facades\Auth::class,
    ‘Blade’ => Illuminate\Support\Facades\Blade::class,

    • Ở mục aliases bạn thử đổi lại thế này xem, làm tương tự mấy cái có sẵn bên trên ấy.
      ‘Form’ => Illuminate\Html\FormFacade::class
      ‘View’ => Illuminate\Html\HtmlFacade::class
      Cái provider cũng làm tương tự cái có sẵn đi.

  13. mình bị lỗi
    ‘composer’ is not recognized as an internal or external command,
    operable program or batch file.
    khi thực hiện composer require illuminate/html
    đã copy C:\xampp\php; vào file path rồi.
    bạn xem giúp mình cái

  14. Mình tìm trong Stackoverflow thì ServiceHtmlProvider ko được sử dụng chính thức nữa.

    http://stackoverflow.com/questions/28541051/class-illuminate-html-htmlserviceprovider-not-found-laravel-5

    Illuminate\Html\HtmlServiceProvider is not a core element anymore. Laravel components that have been removed from the core framework are available on laravelcollective.com your html & forms components can be found here:

    http://laravelcollective.com/docs/5.0/html

    add this to your composer.json :

    “laravelcollective/html”: “~5.0”
    then update composer:

    composer update
    then add providers in config/app.php

    ‘Collective\Html\HtmlServiceProvider’,
    and finally add two aliases in the same file:

    ‘Form’ => ‘Collective\Html\FormFacade’,
    ‘Html’ => ‘Collective\Html\HtmlFacade’,

  15. Use of undefined constant form – assumed ‘form’ (View: C:\xampp\htdocs\laravelfw\resources\views\article\edit.blade.php)
    Mình bị lỗi này, làm đầy đủ rồi mà khô chạy đc, mong AD giúp

  16. Mình có một thắc mắc là mình không thấy nó connect tới cái table nào trong db của mình.

  17. Anh ơi cho em hỏi là lúc cài HtmlServiceProvider em toàn báo lỗi thôi, ko update đc. Nó báo thế này:
    Call to underfine method Illuminate\foundation\Application::getCachedCompilePatch(),…> Em thử php artisan clear-compiled rồi update lại nhưng không được. Nó lại báo lỗi y như thế.

  18. Mình bị lỗi này là sao. lỗi từ mục 5. lấy giá trị từ form. Mong ad giúp

    Whoops, looks like something went wrong.

    1/1
    ReflectionException in RouteDependencyResolverTrait.php line 53:
    Class App\Http\Controllers\Request does not exist
    in RouteDependencyResolverTrait.php line 53
    at ReflectionParameter->getClass() in RouteDependencyResolverTrait.php line 53
    at ControllerDispatcher->resolveMethodDependencies(array(), object(ReflectionMethod)) in RouteDependencyResolverTrait.php line 36
    at ControllerDispatcher->resolveClassMethodDependencies(array(), object(ArticlesController), ‘store’) in ControllerDispatcher.php line 160
    at ControllerDispatcher->call(object(ArticlesController), object(Route), ‘store’) in ControllerDispatcher.php line 107
    at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
    at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
    at ControllerDispatcher->callWithinStack(object(ArticlesController), object(Route), object(Request), ‘store’) in ControllerDispatcher.php line 67
    at ControllerDispatcher->dispatch(object(Route), object(Request), ‘App\Http\Controllers\ArticlesController’, ‘store’) in Route.php line 198
    at Route->runWithCustomDispatcher(object(Request)) in Route.php line 131
    at Route->run(object(Request)) in Router.php line 691
    at Router->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
    at Pipeline->then(object(Closure)) in Router.php line 693
    at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 660
    at Router->dispatchToRoute(object(Request)) in Router.php line 618
    at Router->dispatch(object(Request)) in Kernel.php line 210
    at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
    at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
    at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
    at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
    at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
    at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
    at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
    at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
    at Pipeline->then(object(Closure)) in Kernel.php line 111
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
    at Kernel->handle(object(Request)) in index.php line 53
    at require_once(‘C:\xampp\htdocs\laravel-5\public\index.php’) in server.php line 21

    • Bạn xem thử trong file ArticlesController.php đã có dòng này “use Illuminate\Http\Request;” ở trên đầu, phía dưới namespaces chưa? Nếu chưa thì thêm vào và chạy lại nhé

  19. Bạn ơi, bài viết hay lắm, đừng có làm video mất nhiều thời gian bạn. Thay vì thời gian bạn làm video thì bạn cho ra nhiều bài viết ntn hơn nữa, nói chung là càng nhiều thì càng tốt.

    • ok 🙂 . Video mình chỉ làm trong lúc rảnh rỗi, muốn demo lại cho các bạn xem nó chạy như thế nào, vì có nhiều bạn không làm được. Cám ơn góp ý của bạn, mình sẽ tập trung cho ra nhiều bài viết hơn nữa 🙂

  20. bạn có thể làm seri video hướng dẫn đc ko bạn cho dễ thưc hành !!cho anh e học hỏi kinh nghiệm với?????

  21. Rất tốt. admin có thể thể thêm loạt bài Authentication, hiện tại mình theo dõi các bài admin viết rất dễ hiểu. Tiếng anh của mình cùi lắm, nên đọc document của Laravel thấy rất khó hiểu. thank you!

  22. Cam on ban, bai viet chi tiet lam, mong nhan duoc nhieu bai viet hay hon nua

Trả lời dinhloc Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *