newbie here
I apologize for the cryptic title, I'm new to Laravel and PHP.
I'm building a CTF application using Laravel Jetstream with LiveWire as part of a university project.
Users will submit flags they've found, and I want that data to be compared with a database entry. If they flag is correct, I want this to be shown:
<span
class="inline-flex px-2 text-xs font-semibold leading-5 text-green-800 bg-green-100 rounded-full">
Flag Correct!
</span>
If they got it wrong, I want this to be displayed:
<span
class="inline-flex px-2 text-xs font-semibold leading-5 text-red-800 bg-red-100 rounded-full">
Flag Incorrect
</span>
I have most of this code in place, but I'm not sure how to get the logic or routes to work with LiveWire.
I have a controller, FlagVerification
that has some of the logic, but I'm mainly stuck on how to move this information between the controller and the view, and how to use LiveWire to update what the user sees
Here's my controller so far:
<?php
namespace App\Http\Controllers;
use App\Models\Flag;
class FlagVerification extends Controller
{
function VerifyFlags()
{
// Get first flag from db
$flag1 = Flag::where('id', 1)->value('flags');
// Compare User input with $flag1
// TODO: Pass whatever user entered from table to controller?
if ($flag1 == 'OBR{1FA528F41E8945C}') {
return $flag1;
// If User entered wrong flag, update view.
} else {
// Manipulate table to show "incorrect flag"
return 'Incorrect Flag';
}
}
}
This is what the frontend looks like, it might help give a better idea of the goal imgur[.]com/a/U8ItJuT
I realise this is a lot to ask, so any pointers or tips would be really appreciated
Thank you!
first of all, if you want to get data by id, use: Flag::find($id);
And in your code, you check not user data, you check data from the database with this: OBR{1FA528F41E8945C}
If you want to check data from user with your database data, your code should be something like that:
class FlagVerification extends Controller
{
public function VerifyFlags(Illuminate\Http\Request $request)
{
$flag = Flag::find(1);
// use $flag->name or property name from your model
if ($flag->name === $request->flag) {
return view('path_to_your_response_blade', ['flag' => $flag]);
} else {
// return to view flag false or smth else
return view('path_to_your_response_blade', ['flag' => false]);
}
}
}
And this is your html:
<input type="radio" name="flag" value="test" placeholder="flag1">
Hope I`ve answered on your question :)