Posted on 2 Comments

Write An Charity App With Laravel and Stripe – Migrations

[callaction url=”https://www.youtube.com/user/JPlaya01″ background_color=”#333333″ text_color=”#ffffff” button_text=”Go Now” button_background_color=”#e64429″]Subscribe To My Youtube Page[/callaction]

Laravel Migrations

In this segment we are going to focus on prepping our database. Migrations are a way for you as a developer to manage the schemas for your application’s database tables. This is also where you define the skeleton of your Eloquent models, since their attributes are based off the table they correspond to. For a more in depth understanding of migrations and how they work, go through my Learning Laravel posts.

Command Line Time

Head to the command line and go to the root of the project we created in the last post.  Using the artisan CLI tool, we will generate some migrations. Enter the following command

php artisan make:migration create_charities_table --create=charities

This will create a new migration file in the database/migrations folder. Open it up and copy the following code


<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCharitiesTable extends Migration {
/**
* Run the migrations.
*
* @return void */
  public function up() {
         Schema::create('charities', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users');
            $table->string('name');
            $table->string('description');
            $table->decimal('monthly_amount',5,2);
            $table->timestamps();
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('charities');
    }
}

The first thing we add is a foreign key constraint, so that we can easily identify which charities belong to which user, this will become more apparent in the models post. The next three should be self explanatory; We are collecting the name, description and monthly donation amount for the charity. The monthly_amount will also serve as the amount that is charged for one-time donations. If you noticed there are multiple migrations in the database/migrations folder. We can leave these alone for now, but it would be well worth the time to go through and really understand what those files are doing. In any case when you are ready head back to your command line and issue the following command:

 php artisan migrate

Your database is now migrated. If you received any error, make sure your database details are correct in your .env file located at the root of your project directory. Next we will build our Eloquent models. Stay tuned, and remember if you like what you read SHARE IT, and follow me on Twitter @mastashake08

Posted on Leave a comment

Write An Charity App With Laravel and Stripe – Getting Started

[callaction url=”https://www.youtube.com/user/JPlaya01″ background_color=”#333333″ text_color=”#ffffff” button_text=”Go Now” button_background_color=”#e64429″]Subscribe To My Youtube Page[/callaction]

Laravel and Stripe, What Are We Writing?

In this fourteen part series we will be creating a charity app using Laravel and Stripe. The premise is, users join and add charities they own, and add a bank account for funds to be deposited into. Other patrons go to the charity’s page and can either give an one-time charitable donation, or they may choose to make a recurring donation of $1.00 or more either daily/weekly/monthly. The main purpose of this app is to teach the fundamentals of Stripe and Stripe Connect. By the end of this series you should understand:

  • How to create a Stripe managed account through Stripe Connect
  • Collect payments on your users’ behalf
  • Pay funds out to users’ bank account
  • Some experience with Laravel Spark

Getting Started

Let’s create a new Laravel installation by issuing the following command in your terminal

laravel new ParkerCharity

afterwards cd into your app and run

spark install

 
Answer no to the first question asking if you want to run your migrations, and yes to the other two. That’s it for that, next step is MIGRATIONS!