I am building a Laravel application using Laravel 5.6 in this tutorial. Let's start by creating a new Laravel project.
Prepare your database and setup your database configuration in your .env file
Edit your AppServiceProvider.php file (usually located in app/Providers folder) and inside the boot method set a default string length. We need to do this to handle Migration issue
Inside the file, add the following code block
orcomposer create-project laravel/laravel velreax "5.6.*"
Open the velrex folder. open the composer.json file and add the following dependencies.composer create-project --prefer-dist laravel/laravel velreax
then update the composer libraries"tymon/jwt-auth": "0.5.*", "barryvdh/laravel-cors": "^0.11.0"
Open App.php in the config folder and add the following item into the providers arraycomposer update
and also add the aliases array with the following itemsTymon\JWTAuth\Providers\JWTAuthServiceProvider::class, Barryvdh\Cors\ServiceProvider::class
'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class, 'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
Prepare your database and setup your database configuration in your .env file
Edit your AppServiceProvider.php file (usually located in app/Providers folder) and inside the boot method set a default string length. We need to do this to handle Migration issue
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
By default Laravel 5.6 comes with users table and password reset table migration files. Open the terminal or command prompt and run the command belowThis would create a file in the \database\migrations\ folder with the time stamp appended before the file name, e.g “2018_04_23_094544_create_articles_table.php”.php artisan make:migration create_articles_table
Inside the file, add the following code block
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateArticlesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->string('title');
$table->string('slug')->unique();
$table->text('excerpts');
$table->text('body');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('articles');
}
}
Run the command below in the terminal or command promptThis would creating the tables inside the database.php artisan migrate
Komentar
Posting Komentar