Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Fix Code Style

on: [push]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [8.4]

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: pint

- name: Run Pint
run: pint

- name: Commit linted files
uses: stefanzweifel/git-auto-commit-action@v6
5 changes: 0 additions & 5 deletions app/Http/Controllers/V1/SuggestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ public function store(Trip $trip, SuggestionRequest $suggestionRequest): Redirec
return redirect()->route('trips.show', ['trip' => $trip]);
}

/**
* @param Suggestion $suggestion
* @param Request $request
* @return RedirectResponse
*/
public function vote(Suggestion $suggestion, Request $request): RedirectResponse
{
$validated = $request->validate([
Expand Down
17 changes: 7 additions & 10 deletions app/Http/Controllers/V1/TripController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ class TripController extends Controller
/**
* Display a listing of the resource.
*/
public function index()
public function index(): View
{


$user = auth()->user()->load(['owns', 'trips']);
$trips = [
'owns' => $user->owns,
'invited' => $user->trips
'invited' => $user->trips,
];

return view('trips.index', compact('trips'));

// trips im associated with

}

/**
Expand All @@ -40,9 +37,10 @@ public function index()
public function create(): View
{
//
$users = Cache::remember('listableUsers',3600 , function () {
return User::get(['id','name']);
$users = Cache::remember('listableUsers', 3600, function () {
return User::get(['id', 'name']);
});

return view('trips.create', compact('users'));
}

Expand All @@ -51,7 +49,6 @@ public function create(): View
*/
public function store(TripRequest $tripRequest): RedirectResponse
{
//
$trip = auth()->user()->owns()->create($tripRequest->validated());
$trip->users()->attach($tripRequest->users);

Expand Down Expand Up @@ -88,8 +85,8 @@ public function edit(Trip $trip): View
//
Gate::authorize('update', $trip);
$trip = $trip->load('users:id,name');
$users = Cache::remember('listableUsers',3600 , function () {
return User::get(['id','name']);
$users = Cache::remember('listableUsers', 3600, function () {
return User::get(['id', 'name']);
});

return view('trips.edit', compact('trip', 'users'));
Expand Down
9 changes: 9 additions & 0 deletions app/Models/Suggestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,25 @@ class Suggestion extends Model

protected $fillable = ['description', 'status', 'user_id'];

/**
* @return BelongsTo<User, $this>
*/
public function User(): BelongsTo
{
return $this->belongsTo(User::class);
}

/**
* @return BelongsTo<Trip, $this>
*/
public function Trip(): BelongsTo
{
return $this->belongsTo(Trip::class);
}

/**
* @return HasMany<Vote, $this>
*/
public function Vote(): HasMany
{
return $this->hasMany(Vote::class);
Expand Down
8 changes: 6 additions & 2 deletions app/Models/Trip.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@ class Trip extends Model

/**
* A trip belongs to its creator
*
* @return BelongsTo<User, $this>
*/
public function owner(): BelongsTo
{
return $this->belongsTo(User::class);
}

/**
* @return HasMany
* A trip belongs to its creator
*
* @return HasMany<Suggestion, $this>
*/
public function suggestions(): HasMany
{
return $this->hasMany(Suggestion::class);
}

/**
* @return BelongsToMany
* @return BelongsToMany<User, $this>
*/
public function users(): BelongsToMany
{
Expand Down
10 changes: 9 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,32 @@ protected function casts(): array

/**
* Creator can own many trips
*
* @return HasMany<Trip, $this>
*/
public function owns(): HasMany
{
return $this->hasMany(Trip::class, 'owner_id');
}

/**
* @return HasMany<Suggestion, $this>
*/
public function suggestions(): HasMany
{
return $this->hasMany(Suggestion::class);
}

/**
* @return HasMany<Vote, $this>
*/
public function votes(): HasMany
{
return $this->hasMany(Vote::class);
}

/**
* @return BelongsToMany
* @return BelongsToMany<Trip, $this>
*/
public function trips(): BelongsToMany
{
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ class Vote extends Model
//
protected $fillable = ['type', 'user_id'];

/**
* @return BelongsTo<User,$this>
*/
public function User(): BelongsTo
{
return $this->belongsTo(User::class);
}

/**
* @return BelongsTo<Suggestion,$this>
*/
public function Suggestion(): BelongsTo
{
return $this->belongsTo(Suggestion::class);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"require-dev": {
"barryvdh/laravel-debugbar": "^3.16",
"fakerphp/faker": "^1.23",
"larastan/larastan": "^3.7",
"laravel/pail": "^1.2.2",
"laravel/pint": "^1.25",
"laravel/sail": "^1.41",
Expand Down
Loading