FEATURE: add number of views in page
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user