Laravel App Model codes

This is the codes for the model

 

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Post;
use Carbon\Carbon; //for timestampe

class PostController extends Controller
{
    public function Index() {

    return view('posts.index');

  }


    public function Store() {

      //
      // $current_time = Carbon::now()->toDateTimeString();
      // // echo $date->getTimestamp();
      // // $post = new App\Post; //Class 'App\Http\Controllers\App\Post' not found
      // $post = new \App\Post;
      //
      // $post->title = request('thisTitle');
      // $post->content = request('thisContent');
      // $post->created_at = $current_time;
      // $post->save();

      // OR

      Post::create( request(  ['title','content'] ) );

    // dd(request()->all() );
    // dd(request('thisTitle') );
    // dd(request(['thisTitle','thisContent']) );
    // return redirect ('/myblog/public/posts'); //http://localhost/myblog/public/myblog/public/posts
    return redirect ('/posts');
  }

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *