-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc81d5c
commit f7bdcfb
Showing
13 changed files
with
368 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Purchase; | ||
use App\Models\Ticket; | ||
use App\Models\NewTicket; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class PurchaseController extends Controller | ||
{ | ||
public function create(Request $request) | ||
{ | ||
$validatedData = $request->validate([ | ||
'ticket_id' => 'required|integer', | ||
'ticket_type' => 'required|string|in:tickets,new_tickets', | ||
]); | ||
|
||
$ticketType = $validatedData['ticket_type']; | ||
$ticketId = $validatedData['ticket_id']; | ||
|
||
$ticket = $ticketType == 'tickets' ? Ticket::find($ticketId) : NewTicket::find($ticketId); | ||
|
||
if (!$ticket) { | ||
return redirect()->back()->withErrors(['ticket_not_found' => 'Ticket not found']); | ||
} | ||
|
||
return view('purchase.confirm', compact('ticket', 'ticketType')); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$validatedData = $request->validate([ | ||
'ticket_id' => 'required|integer', | ||
'ticket_type' => 'required|string|in:tickets,new_tickets', | ||
'num_travelers' => 'required|integer|min=1', | ||
'travel_purpose' => 'required|string', | ||
'has_children' => 'required|boolean', | ||
'luggage_type' => 'required|string', | ||
]); | ||
|
||
$ticketType = $validatedData['ticket_type']; | ||
$ticketId = $validatedData['ticket_id']; | ||
|
||
$ticket = $ticketType == 'tickets' ? Ticket::find($ticketId) : NewTicket::find($ticketId); | ||
|
||
if (!$ticket) { | ||
return response()->json(['error' => 'Ticket not found'], 404); | ||
} | ||
|
||
$purchase = Purchase::create([ | ||
'user_id' => Auth::id(), | ||
'ticket_id' => $ticketId, | ||
'ticket_type' => $ticketType, | ||
'num_travelers' => $validatedData['num_travelers'], | ||
'travel_purpose' => $validatedData['travel_purpose'], | ||
'has_children' => $validatedData['has_children'], | ||
'luggage_type' => $validatedData['luggage_type'], | ||
]); | ||
|
||
return response()->json(['message' => 'Purchase confirmed successfully'], 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Purchase extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'user_id', | ||
'ticket_id', | ||
'ticket_type', | ||
'num_travelers', | ||
'travel_purpose', | ||
'has_children', | ||
'luggage_type', | ||
]; | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
|
||
public function ticket() | ||
{ | ||
return $this->morphTo(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
database/migrations/2024_06_06_093146_create_purchases_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreatePurchasesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('purchases', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('user_id')->constrained()->onDelete('cascade'); | ||
$table->foreignId('ticket_id')->constrained()->onDelete('cascade'); | ||
$table->string('ticket_type'); // "new_tickets" or "tickets" | ||
$table->integer('num_travelers'); | ||
$table->string('travel_purpose'); | ||
$table->boolean('has_children'); | ||
$table->string('luggage_type'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('purchases'); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,4 @@ const Panes = () => { | |
); | ||
}; | ||
|
||
export default Panes; | ||
|
||
|
||
|
||
export default Panes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.