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? (36 h 00 min)

You also get:

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

Already a member? Login here

PedroSMaia avatar

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?

PedroSMaia avatar

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

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

Nerijus avatar

@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.

PedroSMaia avatar

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

Nerijus avatar

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

PedroSMaia avatar

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

Nerijus avatar

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

Yuvraj Timalsina avatar

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

public function __construct(public mixed $options)

andywong31 avatar

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?

andywong31 avatar

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

php artisan optimize:clear

seems like its a caching issue

Luis Antonio Parrado avatar
Luis Antonio Parrado

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