Skip to content

Commit cc3d959

Browse files
Refactor thread sharing, user model, routes, and add API middleware
Co-authored-by: bixmatech <bixmatech@gmail.com>
1 parent 61a638e commit cc3d959

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

app/Http/Controllers/ThreadController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
use App\Models\ChatThread;
66
use Illuminate\Http\Request;
7-
use Illuminate\Support\Str;
7+
use Illuminate\Support\Facades\Auth;
88

99
class ThreadController extends Controller
1010
{
1111
public function share(ChatThread $thread)
1212
{
13-
$this->authorize('view', $thread);
13+
if ($thread->user_id !== Auth::id()) {
14+
abort(403);
15+
}
1416
if (!$thread->is_public) {
1517
$thread->update(['is_public' => true]);
1618
}

app/Models/User.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,19 @@ class User extends Authenticatable
1212
/** @use HasFactory<\Database\Factories\UserFactory> */
1313
use HasFactory, Notifiable;
1414

15-
/**
16-
* The attributes that are mass assignable.
17-
*
18-
* @var list<string>
19-
*/
2015
protected $fillable = [
2116
'name',
2217
'email',
2318
'password',
19+
'role',
20+
'credits',
2421
];
2522

26-
/**
27-
* The attributes that should be hidden for serialization.
28-
*
29-
* @var list<string>
30-
*/
3123
protected $hidden = [
3224
'password',
3325
'remember_token',
3426
];
3527

36-
/**
37-
* Get the attributes that should be cast.
38-
*
39-
* @return array<string, string>
40-
*/
4128
protected function casts(): array
4229
{
4330
return [

bootstrap/app.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
$middleware->alias([
1919
'admin' => AdminOnly::class,
2020
]);
21+
$middleware->statefulApi();
22+
$middleware->throttleApi();
2123
})
2224
->withExceptions(function (Exceptions $exceptions): void {
2325
//

routes/web.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use App\Http\Controllers\InstallerController;
66
use App\Http\Controllers\PaymentController;
77
use App\Http\Controllers\CreditPackageController;
8-
use App\Http\Controllers\BlogPostController;
98
use App\Http\Controllers\PageController;
109
use App\Http\Controllers\ThreadController;
1110
use App\Http\Controllers\Admin\PaymentAdminController;
@@ -26,7 +25,6 @@
2625
Route::view('/', 'admin.index')->name('index');
2726
Route::resource('agents', AgentController::class);
2827
Route::resource('packages', CreditPackageController::class)->except(['show']);
29-
Route::resource('blog', BlogPostController::class);
3028
Route::resource('pages', PageController::class);
3129
Route::get('payments', [PaymentAdminController::class, 'index'])->name('payments.index');
3230
Route::post('payments/{payment}/approve', [PaymentAdminController::class, 'approve'])->name('payments.approve');

0 commit comments

Comments
 (0)