Mastering Development

Laravel Validation Array must contain one item where boolean is true

I’m validating question and answers (for test creation). I’d like to ensure that the answers array contains at least one ‘correct’ item. So where answers.*.correct => true. I currently have the following: public function rules() { return [ ‘title’ => ‘required|string|max:255’, ‘test_id’ => ‘required|integer|exists:tests,id’, ‘content’ => ‘required’, ‘answers’ => ‘required|array’, ‘answers.*.text’ => ‘required|string|max:255’, ‘answers.*.correct’ => […]

Development Laravel

How to solve “__construct() must be an instance” error in laravel?

I am facing an error. But i don’t know how to solve this.Someone please help me.I am providing code bellow: **Controller.php** public function store(Request $request){ $this->validate($request, [ ‘title’ => ‘required|max:255’, ‘content’ => ‘required’, ]); $user = Auth::user(); $single_post = $user->posts()->create([ ‘title’ => $request->title, ‘content’ => $request->content, ‘published’ => $request->has(‘published’) ]); $post = Post::all(); broadcast(new ViewPost($post))->toOthers(); […]