There is an increment Builder method for this
https://laravel.com/docs/9.x/queries#increment-and-decrement
Example:
$profile = Profile::where('user_id', auth()->id())->first();
$profile->increment('views');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want my code to work so that when you visit the profiles page it adds 1 to the views column.
@aeothegod you can fetch data from the database using the query builder:
$items = DB::table('table_name')->where('some_column', '=', 'some_value')->get();
Passing this $items variable to a Blade template:
@foreach($items as $item)
<!-- markup -->
{{ $item->column_name }}
@endforeach
Please or to participate in this conversation.