欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

laravel 控制器跳转_Laravel的控制器

程序员文章站 2024-03-22 22:53:04
...

laravel 控制器跳转

For further process we need to know something about it,

为了进一步处理,我们需要了解一些有关它的信息,

  • You can say that the Controller is the entry point of any project or any web-based application because you can assume it's meaning by the name itself.

    您可以说Controller是任何项目或任何基于Web的应用程序的入口点,因为您可以假设名称本身就是它的含义。

  • We make a controller to control our project. It receives HTTP requests, communicates with models and manages the views of our project.

    我们制作一个控制器来控制我们的项目。 它接收HTTP请求,与模型进行通信并管理我们项目的视图。

Laravel的控制器 (Controller in Laravel)

ADD the postcontroller with --resource parameters on CMD,

在CMD上使用--resource参数添加后控制器 ,

    $ php artisan make:controller PostController --resource

Path: "app/http/controller/PostController.php"

路径: “ app / http / controller / PostController.php”

In postcontroller, we use our model (post) model

postcontroller中 ,我们使用模型(post)模型

  • use "App\post" (on top of the file)

    使用“ App \ post” (在文件顶部)

  • public function index{}

    公共职能指数{}

laravel 控制器跳转_Laravel的控制器

Example: PostController.php code for index method.

示例:用于索引方法的PostController.php代码。

use App\Post;
class PostController extends Controller
{
	// Display a listing of the resource.
	public function index()
	{
		$posts = Post::latest()->paginate(5);
		return view('posts.index',compact('posts'))->with('i',(request()->input('page',1) -1) *5);
	}
}

  • 'index' method will show all data from the database to our index view.

    “索引”方法将显示从数据库到索引视图的所有数据。

  • 'paginate' method to sort data in the view.

    'paginate'方法对视图中的数据进行排序。

  • The controller has created, store, show, update and destroy method with index method. We will also be using these methods in the upcoming article with an example or with creating a form.

    控制器已使用索引方法创建,存储,显示,更新和销毁方法。 在后面的文章中,我们还将通过示例或创建表单来使用这些方法。

  • After creating a route declaration in route.php in the controller directory.

    controller目录中的route.php中创建路由声明之后。

  • In the controller directory, the auth folder exists which is pre-defined in Laravel for reset password, Login, and Register.

    controller目录中 ,存在auth文件夹 ,该文件夹在Laravel中预定义,用于重置密码,登录和注册。

Conclusion:

结论:

In this article, we have learnt about the Controller in Laravel. I hope you understood the concept, we will be knowing more about it in the upcoming articles. Have a great day! Happy Learning!

在本文中,我们了解了Laravel中Controller 。 希望您理解这个概念,我们将在以后的文章中进一步了解它。 祝你有美好的一天! 学习愉快!

翻译自: https://www.includehelp.com/laravel/controller.aspx

laravel 控制器跳转