laravel 控制器跳转_Laravel的控制器

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 Controller

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 控制器跳转

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值