GithubHelp home page GithubHelp logo

first-project's Introduction

Midterm Requirements

The goal of this project is to build a simple Q&A website. A visitor should be able to ask questions and leave answers without any authentication.

Here is a working example of what you're going to build.

The styles don't need to match exactly, but you should display all of the same data and have the same URLs, document titles (the title in the browser tab), success messages, and error messages. It should function exactly the same as the example.

Database

Create 2 migrations:

php artisan make:migration create_questions_table
php artisan make:migration create_answers_table

Place the following code in the create_questions_table migration file:

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateQuestionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('questions', function (Blueprint $table) {
            $table->id();
            $table->text('body');
            $table->timestamps();
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('questions');
    }
}

Place the following code in the create_answers_table migration file:

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAnswersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('answers', function (Blueprint $table) {
            $table->id();
            $table->foreignId('question_id');
            $table->text('body');
            $table->timestamps();
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('answers');
    }
}

Now run the migrations.

The Questions Page

For this page, you must use Eloquent.

  1. The question form must be validated. If the form fails validation, it must stay populated with what the user entered, rather than getting reset. The question form must have the following validation rules applied via Laravel's Validation library:
  • Required
  • Minimum length: 5
  • Ends with a question mark ("?"). See the ends_with rule.
  • Must be unique. The same question can't be asked more than once. See the unique rule.

Display validation error messages underneath the textarea in red like in the example.

  1. When a question is successfully created, redirect to that question's page.
  2. A green success alert/notification that contains the question should be shown as a flash message when a question is created. See the example.
  3. The list of questions must be sorted from newest to oldest.
  4. Display questions.created_at formatted like 3/6/2022 at 10:56 PM using PHP's date_format() function. Here are a few examples:
    • date_format('2022-03-06 22:56:02', 'n/j/Y') will produce 3/6/2022
    • date_format('2022-03-06 22:56:02', 'g:i A') will produce 10:56 PM
  5. Display the number of answers that each question contains.
    • Hint: In our class example, let's say I wanted to count how many invoice items there are in an invoice. We could do this via the following using PHP's count() function: count($invoice->invoiceItems).
  6. This page should execute no more than 2 queries on page load. Use the Laravel Debugbar to monitor database queries.

The Answers Page

  1. The answer form must be validated. If the form fails validation, it must stay populated with what the user entered, rather than getting reset. The answer form must have the following validation rules applied via Laravel's Validation library:
  • Required
  • Minimum length: 5

Display validation error messages underneath the textarea in red like in the example.

  1. If a question doesn't have any answers, display "No answers yet! Be the first to answer by using the form below.".
  2. When an answer is successfully created, redirect back to the question page that you submitted your answer on.
  3. A green success alert/notification that contains the answer should be shown as a flash message when an answer is created. See the example.
  4. The list of answers must be sorted from newest to oldest.
  5. The document title (the title in the browser tab) should contain the question like in the example.
  6. Display answers.created_at formatted like 3/6/2022 at 10:56 PM using PHP's date_format() function. Here are a few examples:
    • date_format('2022-03-06 22:56:02', 'n/j/Y') will produce 3/6/2022
    • date_format('2022-03-06 22:56:02', 'g:i A') will produce 10:56 PM

Other Requirements

  1. You must use Blade templating.
  2. You must use a layout file.
  3. All routes must map to a controller.
  4. All URLs must use the route() helper function.
  5. The "Q&A" title should be a link to the home page.

first-project's People

Contributors

zhang-jiahangh avatar ryanzhou7 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.