Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use App\Posts;
- class PostsController extends Controller
- {
- //
- public function index(){
- $posts = Posts::all();
- return view("post.index",compact("posts"));
- }
- public function create(){
- return view("post.create");
- }
- public function store(){
- $post = new Posts;
- $post->title = request("title");
- $post->body = request("body");
- $post->save();
- // or
- // must set $fillable in model
- Posts::create([
- "title" => request("title"),
- "body" => request("body")
- ]);
- return redirect("posts");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement