FEATURE: add number of views in page

This commit is contained in:
Michal Kváček
2016-09-20 01:04:23 +02:00
parent 7a681fd7f7
commit 8bd30d0301
3 changed files with 45 additions and 0 deletions
@@ -50,6 +50,9 @@ class ContentPage extends Controller
throw new \Exception('Cannot access protected resources'); throw new \Exception('Cannot access protected resources');
} }
// add one new "view" for page
$page->view();
// get handler // get handler
$handler = new $page->module_handler; $handler = new $page->module_handler;
+8
View File
@@ -435,4 +435,12 @@ class Content extends Model
// save history // save history
ContentHistory::create($history); ContentHistory::create($history);
} }
public function view()
{
$this->timestamps = false;
$this->viewed ++;
$this->save();
$this->timestamps = true;
}
} }
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddNumberOfViewsOfPage extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('contents', function (Blueprint $table) {
$table->integer('viewed')
->comment('How many times has been this content page displayed?')
->after('updated_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('contents', function (Blueprint $table) {
$table->dropColumn('viewed');
});
}
}