1. Make migration
    php artisan make:migration create_test_table --create=test
  2. database/migrations/TIMESTAMP_create_test_table.php, change ‘up‘ function:
    ...
    public function up()
    {
        Schema::create('test', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title', 255);
            $table->text('content');
            $table->integer('user_id');
            $table->timestamps();
        });
    }
    ....
  3. Migrate
    php artisan migrate
  4.  Make a model
    php artisan make:model Test
  5. app\Test.php (for example):
    ...
    
    protected $guarded = ['id'];
    
    public function user()
    {
           return $this->belongsTo('App/User');
    }
    ...
  6. Make a controller
    php artisan make:controller TestController
  7. app/Http/Controllers/TestControllers.php, add ‘create‘ function:
    ...
    public function create()
    {
          return view('test.create');
    }
  8. routes/web.php
    ...
    Route::get('/test', 'TestController@create');
    ...
  9. Make a request (validation)
    php artisan make:request TestFormRequest
  10. app/Http/Requests/TestFormRequest.php
    ...
    public function authorize()
    {
          return true;
    }
    
    public function rules()
    {
        return [
            'title' => 'required|min:3'
            'content' => 'required|min:10',
        ];
    }
  11. Make a view: resources/test/create.blade.php….
    <form method="post" action="/test">
    ...
          <input name="title" ...
          <textarea name="content" ...
    ...
    </form>
  12. localhost/test

 

Advertisement