Laravel 5.2 and Cashier - laravel

I have added:
"laravel/cashier": "^6.0"
to composer.json
and:
Laravel\Cashier\CashierServiceProvider::class,
to app.php in the providers array in the config folder.
I have then run composer update, but if I do:
php artisan
I do not see the cashier command there. Am I missing a step?

That command appears to be removed in 5.2. In looking at the docs for 5.2 they've been updated and there is no longer a reference to using the artisan helper `$php artisan cashier:table users
Rather is seems you must now create the migration manually rather than using a helper. From the docs:
Update the user table migration(or whichever entity you are associating with your billing):
Schema::table('users', function ($table) {
$table->string('stripe_id')->nullable();
$table->string('card_brand')->nullable();
$table->string('card_last_four')->nullable();
});
Create a subscriptions table:
Schema::create('subscriptions', function ($table) {
$table->increments('id');
$table->integer('user_id');
$table->string('name');
$table->string('stripe_id');
$table->string('stripe_plan');
$table->integer('quantity');
$table->timestamp('trial_ends_at')->nullable();
$table->timestamp('ends_at')->nullable();
$table->timestamps();
});
Then run the migrate command $ php artisan migrate
I wasn't able to find any info on the reason for this change or whether they'll be re-introducing this artisan command in the future. I assume it is by design though.
Click here for more info on creating migrations.
Hope it helps!

Related

Problems with migrations in Laravel 5.5

Something really weird is going on with my Laravel setup. I create some migration files and, when running php artisan migrate after creating each of them, they were successfully run and the tables were created in the database. Now, if I want to run php artisan migrate:refresh --seed, it cannot rollback one of the migrations because it says that migration file doesn't exist.
This is the error:
And this is my migration file:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAssessmentsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('assessments', function (Blueprint $table) {
$table->increments('id');
//TODO - Complete information for this table
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('assessments');
}
}
What's even weirder is that I had to re-create all migrations because it was randomly not creating some of the tables listed on the migrations.
Did anyone face this issue before? Any help is really appreciated.
[UPDATE]
After a while, I realized this is not something from Laravel. For some reason, my Homestead is not viewing those files despite there are there. If I access that folder via SSH (the one inside the vagrant box), the file is not there. If I go to the real folder, it is there. For some reason the box is not synching files properly.
What's even weirder is that I can access and edit the file inside the VMB but it won't list it and won't take into account when running migrations. Here I created a screen-recording showing the problem.
[UPDATE 2]
Just recorded 2 more videos. This is really strange (unless I am missing something).
Video 1.
Video 2.
It seems to be a problem with MacOS High Sierra and Vagrant. In order to fix it, I had to apply this workaround.
Hopefully this will save some time to the ones having the same problem I was having.

How to maintain two migration tables in Laravel Migration

I'm writing a custom migration and I need to maintain those migrations in a separate migration repository table. I override DatabaseMigrationRepository and replace the migration repository function as follows
public function registerRepository()
{
$this->app->bindShared('migration.repository', function($app)
{
$table = $app['config']['database.cf_custom_migrations'];
return new CustomDatabaseMigrationRepository($app['db'], $table);
});
}
And I have registered my custom migration in artisan.php.
But when I call the custom migration command its execution is based on the Default Migration command.
Have anyone tried this before? How can run the Custom Migration command on Custom Migration table?
create a custom command instead of using migrate which is default to laravel.
use that custom command to run your custom migrations.
hope it helps

How to access Session data from database

I want to access session data from database. Currently, I have changed default setting in session.php to database so that I can capture all the session columns in DB. But now I want to access these in my code. Do I need to create some session model or it's present out of the box just like user.php. Please help me.
You should create sessions table with these commands:
php artisan session:table
composer dump-autoload
php artisan migrate
Or you could manually create migration and run it, an example from documentation:
Schema::create('sessions', function ($table) {
$table->string('id')->unique();
$table->text('payload');
$table->integer('last_activity');
});
After doing that, you can just use sessions as usual with Session:: facade or sessions() helper:
session()->flash('message', 'Success!');
Update
If you need to access table data directly, you could do this:
DB::table('sessions')->get();
Or you could create SessionData() model and do this:
SessionData::all();

Create tables in Laravel 4 with Schema Builder without Migrations on shared hosting

Well, I have a web application and I want to create a teable with Schema Builder, and I cannot Create a migration in a shared hosting, what can you suggest to make a table with Schema?
Schema::create('users', function($table)
{
$table->increments('id');
});
ps. I want to use specifically Laravel's Schema Builder to create tables
You can solve this by creating migrations and a install route. From which you can call some thing like this
Artisan::call('migrate');
for more info look at this Run Artisan Commands Form Route or Controller
Have you tried using Laravel's Routing to run schema builder ?
Route::get('/', function () {
Schema::create('table', function($table) {
$table->increments('id');
});
return "done.";
});

Maintain sessions in Laravel 4

I don't know how to maintain and work with sessions. As I am a newbie in Laravel 4.
I have created a table as follows:
class Sessions extends Migration
{
Schema::create('sessions', function($table)
{
$table->string('id')->unique();
$table->text('payload');
$table->integer('last_activity');
});
}
Is this correct?
Step 1: php artisan session:table
Step 2: composer dump-autoload
Step 3: php artisan migrate
if you have setup multiple environment on your laravel app then
php artisan migrate --env=ENVIRONMENT_NAME
Step 4: Change the default driver on /app/config/session.php to
'driver'=>'database',
if you have multiple Databases configured on your L4 app, then configure the connection on
/app/config/session.php
'connection'=>CONNECTION_NAME

Resources