Skip to main content

Admin: Add Questions to Quiz with Select2

Premium
7 min read

In this part, we will create a Blade component for Select2 and will use it for selecting questions for a quiz.

questions select2 input

So, first let's create the component and add scripts...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (31 h 16 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

P
PedroSMaia ✓ Link copied!

Hello I am having an erro "trim(): Argument #1 ($string) must be of type string, array given"

select-list-blade file

quiz-form.blade file

what can i do to fix this error?

P
PedroSMaia ✓ Link copied!

select-list-blade file - https://prnt.sc/oSt058CovRWc

quiz-form.blade file - https://prnt.sc/GcAHvqV9pN19

N
Nerijus ✓ Link copied!

@PedroSMaia it's a very wierd error that only some people get. How does your app/View/Components/SelectList.php look? But adding props options to the component should fix error.

P
PedroSMaia ✓ Link copied!

@Nerijus my app/View/Components/SelectList.php print is on the link bellow https://prnt.sc/t9u0HSGJP8-4

N
Nerijus ✓ Link copied!

Sorry wrong file, I meant app/Http/View/Components/SelectList.php. But have you tried adding props for options to the blade file?

P
PedroSMaia ✓ Link copied!

Hi again, my file app/Http/View/Components/SelectList.php is in the printscreen bellow https://prnt.sc/FGPNaXeOQyJt

i don't understand what do you say about props

N
Nerijus ✓ Link copied!

Your SelectList.php is different from the in this tutorial.

YT
Yuvraj Timalsina ✓ Link copied!

@PedroSMaia, you are missing parameters inside construct method of Selectlist.php

public function __construct(public mixed $options)

A
andywong31 ✓ Link copied!

i have the same error as @PedroSMaia, i added this inside my SelectList.php:

public function __construct(public mixed $options)

and now a different error occurs:

"Unresolvable dependency resolving Parameter #0 mixed $options in class App\View\Components\SelectList"

help anyone?

A
andywong31 ✓ Link copied!

i just solved my problem. i ran the following command:

php artisan optimize:clear

seems like its a caching issue

LA
Luis Antonio Parrado ✓ Link copied!

If you are working with Livewire 3 must replace the event livewire:load by livewire:init