Level 51
Why don't you use session for pass count number between routes
1 like
I would like to create a counter which counts visited pages for each user. The counter should still increase between different routes!
namespace App\Repositories;
class CounterRepository
{
protected $_times = 0;
public $message = "Hello World! We've met %d times!";
public function sayHello()
{
echo sprintf($this->message, $this->_times);
$this->_times++;
}
}
namespace App\Providers;
use App\Repositories\CounterRepository;
use Illuminate\Support\ServiceProvider;
class CounterProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
echo "boot ";
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
echo "register ";
$this->app->bind('Counter', 'App\Repositories\CounterRepository', true);
}
}
I tried to do it with Laravel Shared Services. But every time the route is changing, the counter starts at 0.
Object can be stored in session ...
http://stackoverflow.com/questions/132194/php-storing-objects-inside-the-session
Please or to participate in this conversation.