New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guide needed #23
Comments
anyone can help? |
It normally will take people a while to respond. 😄 Anyway, regarding your first question. What would your alternative be to a controller? You should be able to use this with route closures, but it's highly recommended to use controllers instead. Regarding your second question, the example code you've mentioned is for managing the view count. The comments for each line are pretty self-explanatory. If you wanted to display this post has been visited {{ $post->page_visits }} times. |
@pxgamer hi, would you mind help me with controller method? I couldn't find any sample code for that matter. What should I do to store data of each posts visits? |
For example with a resource:
|
Hi, As a non native English speaker, it's a little bit hard to write an answer very fast but I see that @pxgamer has already answered your questions. Thanks for the help @pxgamer 😀. Also! To get the formatted number, you should use this post has been visited {{ $post->page_visits_formatted}} times. |
First of all I would like thank you so much @pxgamer & @cyrildewit , and as my last question: I want to get this data in chart as google analytics does such as: prduct 1 50 visits
product 30 30 visits
product 10 11 visits
//and so on well I'm using ChartJs package and there to load this package database I have issue which is normally like $chart = Charts::database(User::all(), 'bar', 'highcharts')
//.... but in this case my database name is |
What does I think you could do someting like: $productViewsChart = Charts::database(Product::all(), 'bar', 'highcharts') Edit: Is this the correct package that you're using: https://github.com/ConsoleTVs/Charts |
@cyrildewit exactly that's the package, I do not have any issue with charts package but my issue was with your package database naming, as you see protected $table = 'page-visits'; now I need to get my products title as value for those counted visits but I can't. here is my method to that: $chartjson = Pagevisit::all()->toJson();
$chartjsontitle =
DB::table('products')
->join('page-visits', function ($join) {
$join->on('products.id', '=', 'page-visits.visitable_id');
})->get();
$value = collect($chartjsontitle)->toArray();
$chart4 = Charts::database($chartjson, 'bar', 'highcharts')
->elementLabel("Total")
->dimensions(1000, 500)
->responsive(false)
->values('visitable_id')
->labels($value); PS: I know this question mostly related to chartjs package but the reason I'm asking it here is if you think i should put some relation in my created model for |
If I'm right you want to have a bar chart that shows the total page views per product? X-axis: Product name I would do something like this: $products = Product::all(); // Get all the products (included with ->page_views)
$productViewsChart = Charts::database('bar', 'highcharts')
->elementLabel('Total')
->dimensions(1000, 500)
->responsive(false)
->values($products->pluck('page_views'))
->labels($product->pluck('name')); To use the package provided Eloquent model for the page views table: |
Hi,
Do I have need any controller method in order to save data or no?
these codes
are just to show visits numbers or what exactly? (i mean frontend such as
this post visited 1.000 times
like that?)Thanks.
The text was updated successfully, but these errors were encountered: