php artisan route:listecho App\Post::count();
Creates new post in posts table using tinker from terminal$post = new App\Post();
$post->title = 'the post title';
$post->content = 'the post body';
$post->save();
Deletes the newly created post$post->delete();php artisan tinkerSchema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->mediumText('content');
$table->timestamps();
});
$table->id() - creates bigint(20) unsigned auto-increment field
$table->string('title') - creates varchar(255) utf8mb4_unicode_ci field
$table->mediumText('content') - creates mediumtext utf8mb4_unicode_ci field
$table->timestamps() - creates created_at and updated_at timestamps.env file contains database config information that needs to be changed
to use the databaseDB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lara4db
DB_USERNAME=root
DB_PASSWORD=Post php artisan make:model Post With the following basic content<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
//
}
Creates Post model and also migrations to create table for the modelphp artisan make:model Post -mThe migration file location isdatabase/migrations/2020_09_02_041219_create_posts_table.phpPosts php artisan make:controller PostsController With the following basic content<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class Postscontroller extends Controller
{
//
}
Creates controller and empty methods in it (with appropriate comments)php artisan make:controller PostsController --resourceThe methods are:
index() - Displays a list of the resource.
create() - Shows the form for creating a new resource
store(Request $request) - Stores a newly created resource in storage
show($id) - Displays the specified resource
edit($id) - Shows the form for editing the specified resource
update(Request $request, $id) - Updates the specified resource in storage
destroy($id) - Removes the specified resource from storage