Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

flusinerd's avatar

Method Illuminate\Validation\Validator::validate does not exist

Hello, I cant get the validate method working: My Controller:

<?php

namespace App\Http\Controllers;

use App\Artikel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Resources\artikelResource as artikelResource;



class ArtikelController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return artikelResource::collection(Artikel::all());
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        return Artikel::create($request->all());
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Artikel  $artikel
     * @return \Illuminate\Http\Response
     */
    public function show(Artikel $artikel)
    {
        return new artikelResource($artikel);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Artikel  $artikel
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Artikel $artikel)
    {
        $this->validate($request,[
            'benennung' => 'required'|'string'|'max:191'|'min:1',
            'aktiv' => 'required'|'boolean'
        ]);
        $artikel->update($request->all());
        return response()->json($artikel->fresh(), 200);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Artikel  $artikel
     * @return \Illuminate\Http\Response
     */
    public function destroy(Artikel $artikel)
    {
        $result = $artikel->delete();
        if ($result == true){
            http_response_code(204);
        } else {
            http_response_code(404);
        }
        return;
    }
}

Any help is appriciated

0 likes
5 replies
Cronix's avatar

try

$request->validate([
    'benennung' => 'required|string|max:191|min:1',
    'aktiv' => 'required|boolean'
]);

Edit: Removed extra quotes. The rules should be a single string with the individual rules separated by pipes...

4 likes
flusinerd's avatar

Nope I didnt, what was the change? Edit: NVM

1 like
Cronix's avatar

See the updated code and how the rules are, with the note under it

1 like

Please or to participate in this conversation.