Làm cách nào để chỉnh sửa và xóa trong Laravel?

Hướng dẫn/bài viết dành cho người mới bắt đầu này chỉ ra cách bạn có thể tạo một hệ thống hoặc ứng dụng CRUD [Tạo, Đọc, Cập nhật, Xóa] đơn giản/cơ bản bằng cách sử dụng Laravel. Laravel là một PHP MVC Framework mã nguồn mở phổ biến với nhiều tính năng phát triển nâng cao

Cài đặt Laravel đã được giải thích tại đây

Mục lục

  • Cấu trúc thư mục ứng dụng Laravel
  • Công cụ dòng lệnh thủ công
  • Tạo nên cơ sở dữ liệu
  • Cài đặt cấu hình cơ sở dữ liệu
  • Tạo bảng
  • Thêm dữ liệu thử nghiệm vào bảng cơ sở dữ liệu
  • Tạo mô hình
  • Lộ trình
  • Tạo bộ điều khiển
  • Lượt xem

Cấu trúc thư mục ứng dụng Laravel

Sau khi cài đặt thành công Laravel, bạn cần biết về cấu trúc ứng dụng [cấu trúc thư mục] của Laravel. Thư mục gốc của Laravel chứa các thư mục sau. Các thư mục con của thư mục


php artisan cache:clear
2 cũng được liệt kê bên dưới


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies

Công cụ dòng lệnh thủ công

Điều quan trọng khác cần hiểu là công cụ dòng lệnh Artisan. Laravel bao gồm một giao diện dòng lệnh có tên ‘Artisan’. Nó dựa trên Thành phần Bảng điều khiển Symfony

Artisan chứa rất nhiều lệnh hữu ích cho việc phát triển ứng dụng. Để xem danh sách tất cả các lệnh Artisan, bạn cần vào thư mục gốc của Laravel và chạy lệnh sau


php artisan list

Bạn sẽ thấy danh sách các lệnh khả dụng sau khi chạy lệnh trên


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files

Như bạn có thể thấy ở trên, có nhiều lệnh thực hiện các công việc hữu ích khác nhau. Bạn có thể xóa Cache bằng một lệnh duy nhất. Bạn có thể chạy các tác vụ theo lịch trình, tạo các bộ điều khiển, sự kiện khác nhau, v.v. các lớp học, v.v.

Ví dụ: để xóa bộ đệm ứng dụng Laravel của bạn, bạn chỉ cần chạy lệnh sau


php artisan cache:clear

Chúng tôi sẽ sử dụng các lệnh thủ công sau trong hướng dẫn này

Tạo nên cơ sở dữ liệu

Sau khi chúng ta có một số hiểu biết về cấu trúc thư mục/ứng dụng của Laravel và về Artisan CLI, bây giờ chúng ta có thể tiếp tục tạo ứng dụng CRUD [Tạo, Đọc, Cập nhật, Xóa] cơ bản trong Laravel

Trước hết, chúng ta cần tạo một cơ sở dữ liệu mới và một bảng bên trong cơ sở dữ liệu mới được tạo. Chúng tôi sẽ đặt tên cơ sở dữ liệu của chúng tôi là


php artisan cache:clear
3 và tạo một bảng tên là

php artisan cache:clear
4 bên trong cơ sở dữ liệu

php artisan cache:clear
5

Đây là truy vấn MySQL để tạo cơ sở dữ liệu

________số 8

Cài đặt cấu hình cơ sở dữ liệu

Sau khi tạo cơ sở dữ liệu, bạn cần nhập tên cơ sở dữ liệu và thông tin đăng nhập cơ sở dữ liệu vào tệp cài đặt cấu hình của Laravel. Tệp cấu hình cơ sở dữ liệu của Laravel có tại


php artisan cache:clear
6

Trong tệp này, bạn sẽ tìm thấy kết nối được xác định cho các cơ sở dữ liệu khác nhau như sqlite, mysql và pssql. Chúng tôi sẽ sử dụng cơ sở dữ liệu MySQL. Do đó, chúng tôi sẽ chỉ cập nhật thông tin cho cơ sở dữ liệu mysql

Tên cơ sở dữ liệu của ứng dụng của chúng tôi trong hướng dẫn này là


php artisan cache:clear
3. Tên người dùng cơ sở dữ liệu trong hệ thống của tôi là

php artisan cache:clear
8 và mật khẩu cũng là

php artisan cache:clear
8. Máy chủ cơ sở dữ liệu cho máy cục bộ của tôi là ________ 80 và cổng là ________ 81. Đây là bản cập nhật được thực hiện bởi bên tôi. Bạn phải cập nhật nó theo cài đặt cơ sở dữ liệu của bạn


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
5

Để sử dụng các lệnh cơ sở dữ liệu từ Artisan Command Line Tool, bạn cũng cần cập nhật cài đặt cơ sở dữ liệu trong tệp


CREATE DATABASE test;
2 vì Artisan tìm nạp cài đặt cơ sở dữ liệu từ tệp

CREATE DATABASE test;
3. Đây là bản cập nhật. tập tin env trên máy tính của tôi


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
8

Tạo bảng

Bạn có thể tạo hoặc sửa đổi các bảng đơn giản thông qua các truy vấn SQL hoặc từ GUI như phpMyAdmin. Tuy nhiên, Laravel cung cấp cho bạn một tùy chọn khác để làm như vậy. Nó được gọi là


CREATE DATABASE test;
4. Với Laravel Migrations, bạn có thể tạo/sửa đổi các bảng cơ sở dữ liệu từ mã PHP

Chúng tôi sẽ tạo một bảng có tên


CREATE DATABASE test;
5. Dưới đây là các bước để làm như vậy

  • Mở terminal/dấu nhắc lệnh
  • Chuyển đến thư mục gốc laravel của bạn
  • Trong trường hợp của tôi [Ubuntu 16. 04] nó sẽ là

php artisan list
1
  • Chạy lệnh sau

php artisan list
2

Thao tác này sẽ tạo bảng


CREATE DATABASE test;
6 trong cơ sở dữ liệu

php artisan cache:clear
5 của bạn

  • Bây giờ, hãy chạy lệnh sau

php artisan list
5

Điều này sẽ tạo một lớp mới có tên là


CREATE DATABASE test;
8 tại

CREATE DATABASE test;
9. tên create_news_table đứng trước giá trị ngày

Lớp


CREATE DATABASE test;
8 sẽ có 2 hàm rỗng là

DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
51 và

DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
52. Mã tạo bảng phải được thêm vào hàm up[] và mã xóa bảng phải được thêm vào hàm down[]

Đây là lớp


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
53 được cập nhật


php artisan list
0

Ghi chú. Chạy lệnh sau sẽ thêm mã lược đồ cơ bản vào hàm up[] và down[] của lớp di chuyển


php artisan list
1

Chạy lệnh sau để thực thi lớp di chuyển


php artisan list
2

Bảng


CREATE DATABASE test;
5 đã được tạo

Thêm dữ liệu thử nghiệm vào bảng cơ sở dữ liệu

Đây là tùy chọn. Nếu bạn muốn thêm dữ liệu mẫu/thử nghiệm vào bảng cơ sở dữ liệu của mình thì bạn có thể thực hiện việc này với các lớp hạt giống của Laravel. Phương pháp này còn được gọi là


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
55

Trong ví dụ này, chúng tôi sẽ thêm một số dữ liệu thử nghiệm vào bảng


CREATE DATABASE test;
5 của bạn

  • Chạy lệnh sau trên terminal/command-Prompt

php artisan list
3

Điều này sẽ tạo một lớp mới có tên là


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
57 tại

DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
58

Lớp


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
57 sẽ có một hàm trống

DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
80. Mã chèn dữ liệu nên được thêm vào hàm run[]

Đây là lớp


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
81 được cập nhật


php artisan list
4

Chạy lệnh sau để thực thi hàm


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
82 của lớp

DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
83. Điều này sẽ thêm dữ liệu vào bảng

DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
84


php artisan list
5

Sử dụng Faker PHP Library để tạo dữ liệu giả mạo

Chúng tôi cũng có thể sử dụng Thư viện Faker để tạo dữ liệu giả cho bảng cơ sở dữ liệu của mình. Đây là lớp NewsTableSeeder sử dụng thư viện Faker


php artisan list
6

Tạo mô hình

Các lớp mô hình được sử dụng cho các hoạt động cơ sở dữ liệu như truy vấn bảng cơ sở dữ liệu hoặc chèn/cập nhật bản ghi trong bảng cơ sở dữ liệu. Laravel sử dụng Eloquent ORM [Object Relational Mapper] để triển khai các tác vụ cơ sở dữ liệu. Trong đó, mỗi bảng cơ sở dữ liệu được liên kết với một lớp Mô hình

Chạy lệnh sau để tạo lớp Model cho bảng


CREATE DATABASE test;
5


php artisan list
7

Lớp mô hình


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
86 sẽ được tạo tại

DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
87

Bạn cần thêm tên bảng, khóa chính của bảng, v.v. trong lớp


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
88

Đây là lớp


DIRECTORY       DESCRIPTION
/app            contains core code of your application
/app/Console    contains all of your Artisan commands
/app/Events     contains event classes
/app/Exceptions contains exception handling classes
/app/Http       contains controllers, middleware, and requests
/app/Jobs       contains jobs that can be queued
/app/Listeners  contains handler classes for events
/app/Policies   contains authorization policy classes
/bootstrap      contains files required by the bootstrap framework and configure autoloading
/config         contains the application configuration files
/database       contains database migrations and seeds. It is also used to store the SQLite database.
/public         contains the front controllers and assets like images, CSS, JavaScript etc.
/storage        contains compiled blade templates, filed based sessions, file caches & other files generated by the framework.
/tests          contains automated unit tests
/vendor         contains composer dependencies
88 được cập nhật


php artisan list
8

Lộ trình

Trước khi chuyển sang Bộ điều khiển, trước tiên chúng tôi xem tệp tuyến đường. Tệp tuyến đường có tại


php artisan list
10. Nói chung, việc sử dụng tệp định tuyến là để kết nối URL yêu cầu với các phương thức của Bộ điều khiển

Dưới đây là một ví dụ tuyến đường cơ bản


php artisan list
9

Bạn sẽ nhận được 'Xin chào thế giới' được in khi bạn duyệt http. //your-laravel-site/foo

Trong lộ trình trên, chúng tôi đã viết một số mã tĩnh. Bây giờ chúng ta sẽ viết một route mới sẽ liên kết đến một chức năng/hành động của lớp NewsController của chúng ta


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files
0

Điều này sẽ định tuyến đến hàm index[] của News controller class khi chúng ta duyệt http. //your-laravel-site/tin tức

Đối với ứng dụng của chúng tôi, chúng tôi cần đặt đoạn mã sau vào tệp


php artisan list
10 của ứng dụng


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files
1

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

Trong lớp Trình điều khiển, chúng tôi viết tất cả các logic để lấy dữ liệu từ bảng cơ sở dữ liệu, xử lý nó và chuyển nó đến các khung nhìn. Các lớp điều khiển được lưu trong thư mục ______ 212

Chạy đoạn mã sau để tạo lớp trình điều khiển


php artisan list
13


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files
2

Điều này sẽ tạo lớp


php artisan list
14 tại

php artisan list
15. Sử dụng

php artisan list
16 sẽ tạo các tuyến CRUD cơ bản trong lớp trình điều khiển Tin tức. Nó sẽ tạo các hàm trống có tên là chỉ mục, tạo, cập nhật, hủy, v.v.

Trong các chức năng của bộ điều khiển, chúng tôi gọi lớp mô hình của mình, tìm nạp dữ liệu, xử lý và chuyển dữ liệu để xem tệp

Trong hàm index[] bên dưới, dữ liệu Tin tức được tìm nạp trước tiên và sau đó mẫu dạng xem được trả về bằng cách sử dụng phương thức view[].
Trong hàm store[], yêu cầu gửi biểu mẫu được tìm nạp, sau đó dữ liệu đầu vào được lưu vào cơ sở dữ liệu bằng phương thức create[] và sau đó được chuyển hướng đến tin tức. trang mục lục.

Đây là lớp


php artisan list
13 cập nhật được sử dụng cho ứng dụng của hướng dẫn này


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files
3

Lượt xem

Lượt xem là các tệp html có trong thư mục


php artisan list
18. Laravel sử dụng công cụ tạo khuôn mẫu Blade trong các khung nhìn giúp sử dụng các vòng lặp và các điều kiện if/else như PHP trong tệp html của khung nhìn

Laravel sử dụng công cụ tạo khuôn mẫu lưỡi, vì vậy các tệp xem nên được đặt tên là


php artisan list
19

Như bạn có thể thấy ở trên, trong hàm


php artisan list
20 của lớp

php artisan list
21, chúng tôi đã chuyển dữ liệu tin tức vào chế độ xem

php artisan list
22. Điều này có nghĩa là chế độ xem phải được lưu trữ trong

php artisan list
23

Đối với hướng dẫn này, trước tiên chúng tôi sẽ tạo một mẫu chính nơi chúng tôi bao gồm/xác định tiêu đề, tiêu đề, nội dung và chân trang. Sau đó, chúng tôi mở rộng mẫu chính cho các trang khác trong ứng dụng của mình. Chúng tôi cũng hiển thị thông báo flash thành công và lỗi trên mẫu chính

Đây là mẫu chính của chúng tôi [______224]


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files
4


php artisan list
25 sẽ được mở rộng tổng thể. lưỡi. mẫu php và sau đó hiển thị mục tin tức trong phần nội dung. Dữ liệu tin tức cho mẫu chỉ mục đến từ hàm

php artisan list
26 của lớp

php artisan list
27

Trong mẫu chỉ mục, bạn cũng sẽ thấy biểu mẫu Xóa. Hành động xóa đi đến hàm


php artisan list
28 của lớp

php artisan list
27. Thay vì liên kết, nút sẽ được sử dụng cho mục đích Xóa trong Laravel


php artisan list
50 hiển thị liên kết phân trang


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files
5

Trang mục lục tin tức sẽ như bên dưới

Bây giờ, chúng tôi chuyển sang tạo một biểu mẫu thêm tin tức. Chúng ta chỉ cần viết cú pháp html để tạo biểu mẫu. Tuy nhiên, Laravel cũng cung cấp cho chúng ta tùy chọn tạo biểu mẫu bằng gói


php artisan list
51

Để cài đặt gói này, hãy cập nhật tệp


php artisan list
52. Thêm điều này


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files
6

Sau đó chạy lệnh cập nhật trình soạn thảo trên thiết bị đầu cuối


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files
7

Thao tác này sẽ cài đặt gói laravelcollective/html vào ứng dụng laravel của bạn

Sau đó, chỉnh sửa


php artisan list
53


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files
8

Bây giờ, tạo tệp mẫu để thêm tin tức. Hành động thêm biểu mẫu tin tức gửi đến hàm


php artisan list
54 của lớp

php artisan list
27


php artisan list
56


Laravel Framework version 5.2.41

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  clear-compiled      Remove the compiled class file
  down                Put the application into maintenance mode
  env                 Display the current framework environment
  help                Displays help for a command
  list                Lists commands
  migrate             Run the database migrations
  optimize            Optimize the framework for better performance
  serve               Serve the application on the PHP development server
  tinker              Interact with your application
  up                  Bring the application out of maintenance mode
 app
  app:name            Set the application namespace
 auth
  auth:clear-resets   Flush expired password reset tokens
 cache
  cache:clear         Flush the application cache
  cache:table         Create a migration for the cache database table
 config
  config:cache        Create a cache file for faster configuration loading
  config:clear        Remove the configuration cache file
 db
  db:seed             Seed the database with records
 event
  event:generate      Generate the missing events and listeners based on registration
 key
  key:generate        Set the application key
 make
  make:auth           Scaffold basic login and registration views and routes
  make:console        Create a new Artisan command
  make:controller     Create a new controller class
  make:event          Create a new event class
  make:job            Create a new job class
  make:listener       Create a new event listener class
  make:middleware     Create a new middleware class
  make:migration      Create a new migration file
  make:model          Create a new Eloquent model class
  make:policy         Create a new policy class
  make:provider       Create a new service provider class
  make:request        Create a new form request class
  make:seeder         Create a new seeder class
  make:test           Create a new test class
 migrate
  migrate:install     Create the migration repository
  migrate:refresh     Reset and re-run all migrations
  migrate:reset       Rollback all database migrations
  migrate:rollback    Rollback the last database migration
  migrate:status      Show the status of each migration
 queue
  queue:failed        List all of the failed queue jobs
  queue:failed-table  Create a migration for the failed queue jobs database table
  queue:flush         Flush all of the failed queue jobs
  queue:forget        Delete a failed queue job
  queue:listen        Listen to a given queue
  queue:restart       Restart queue worker daemons after their current job
  queue:retry         Retry a failed queue job
  queue:table         Create a migration for the queue jobs database table
  queue:work          Process the next job on a queue
 route
  route:cache         Create a route cache file for faster route registration
  route:clear         Remove the route cache file
  route:list          List all registered routes
 schedule
  schedule:run        Run the scheduled commands
 session
  session:table       Create a migration for the session database table
 vendor
  vendor:publish      Publish any publishable assets from vendor packages
 view
  view:clear          Clear all compiled view files
9

Đây là mẫu để hiển thị tin tức cá nhân. URL sẽ là


php artisan list
57. Cái này gọi hàm

php artisan list
58 của lớp

php artisan list
27


php artisan list
00


php artisan cache:clear
0

Đây là mẫu để chỉnh sửa tin tức. Hành động post của form sửa tin chuyển đến hàm


php artisan list
01 của lớp

php artisan list
27

Làm cách nào để chỉnh sửa và xóa trong laravel?

/subjects/store/{id} – Mở chế độ xem chủ đề chỉnh sửa theo id. /subjects/update/{id} – Gửi biểu mẫu chỉnh sửa để cập nhật bản ghi theo id. /subjects/delete/{id} – Xóa chủ đề theo id .

Làm cách nào để cập nhật và xóa dữ liệu trong laravel?

getuserData[] – Tìm nạp tất cả các bản ghi từ bảng người dùng và trả lại. Nếu $id khác 0 thì chọn ghi theo id
insertData[] – Từ chức năng này chèn một bản ghi mới. Kiểm tra tên người dùng tồn tại hay không trong bảng người dùng. .
updateData[] – Từ chức năng này, bản ghi cập nhật. .
deleteData[] – Từ chức năng này xóa bản ghi

Làm cách nào để chỉnh sửa dữ liệu bằng laravel?

Chúng tôi có thể cập nhật các bản ghi bằng cách sử dụng mặt tiền DB với phương thức cập nhật . Cú pháp của phương thức cập nhật như trong bảng sau. Chạy một câu lệnh cập nhật đối với cơ sở dữ liệu.

Làm cách nào để chỉnh sửa mã laravel?

1 câu trả lời .
Chuyển đến thư mục dự án laravel của bạn
Sau đó vào tài nguyên ---> thư mục lượt xem
Bây giờ bạn có thể thấy. tập tin php lưỡi. Mở và chỉnh sửa mã html của bạn bằng trình chỉnh sửa của bạn

Chủ Đề