---
agentTools:
  projectIndex: https://laravel-angular.readme.io/llms.txt
---

# Laravel Controller

Now we need to write the create function inside the controller.

[block:code]
{
  "codes": [
    {
      "code": "<?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Post;\nuse App\\Http\\Requests;\nuse Illuminate\\Http\\Request;\n\nclass CreatePostController extends Controller\n{\n  public function create(Request $request)\n  {\n   \t\t$this->validate($request, [\n        'name'  => 'required',\n        'topic' => 'required',\n        ]);\n    \n      $post = new Post;\n      $post->name = $request->input('name');\n      $post->topic = $request->input('topic');\n      $post->save();\n    \n      return response()->success(compact('post'));\n  }\n  \n}",
      "language": "php",
      "name": "CreatePostController.php"
    }
  ]
}
[/block]

[block:callout]
{
  "type": "warning",
  "body": "This tutorial assumes you have created the model and appropriate migration for the table `posts`.\n\nIf you're not comfortable with this, make sure to follow the official [laravel tutorials](https://laravel.com/docs/5.3/quickstart-intermediate) before reading this."
}
[/block]

> Prefer a screencast?

[block:html]
{
  "html": "<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/_ZWV9KBK2N8\" frameborder=\"0\" allowfullscreen></iframe>"
}
[/block]